Skip to content

Commit 1c9a0fa

Browse files
committed
Center titles in text-only segemented control with Box selection style
1 parent 04763b2 commit 1c9a0fa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

HMSegmentedControl/HMSegmentedControl.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,10 @@ - (void)drawRect:(CGRect)rect {
253253
stringHeight = size.height;
254254

255255
// Text inside the CATextLayer will appear blurry unless the rect values are rounded
256-
CGFloat y = roundf(CGRectGetHeight(self.frame) - self.selectionIndicatorHeight)/2 - stringHeight/2 + ((self.selectionIndicatorLocation == HMSegmentedControlSelectionIndicatorLocationUp) ? self.selectionIndicatorHeight : 0);
257-
256+
BOOL locationUp = (self.selectionIndicatorLocation == HMSegmentedControlSelectionIndicatorLocationUp);
257+
BOOL selectionStyleNotBox = (self.selectionStyle != HMSegmentedControlSelectionStyleBox);
258+
259+
CGFloat y = roundf((CGRectGetHeight(self.frame) - selectionStyleNotBox * self.selectionIndicatorHeight)/2 - stringHeight/2 + self.selectionIndicatorHeight * locationUp);
258260
CGRect rect;
259261
if (self.segmentWidthStyle == HMSegmentedControlSegmentWidthStyleFixed) {
260262
rect = CGRectMake((self.segmentWidth * idx) + (self.segmentWidth - stringWidth)/2, y, stringWidth, stringHeight);

0 commit comments

Comments
 (0)