Skip to content

Commit f7c7c30

Browse files
committed
Clean up inconsistent rounding on iOS
1 parent 489c60a commit f7c7c30

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

TOSegmentedControl/TOSegmentedControl.m

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,12 @@ - (void)commonInit {
140140
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
141141
self.trackView.layer.masksToBounds = YES;
142142
self.trackView.userInteractionEnabled = NO;
143-
#ifdef __IPHONE_13_0
144-
if (@available(iOS 13.0, *)) {
145-
self.trackView.layer.cornerCurve = kCACornerCurveContinuous;
146-
}
147-
#endif
143+
148144
[self addSubview:self.trackView];
149145

150146
// Create thumb view
151147
self.thumbView = [[UIView alloc] initWithFrame:CGRectMake(2.0f, 2.0f, 100.0f, 28.0f)];
152148
self.thumbView.layer.shadowColor = [UIColor blackColor].CGColor;
153-
#ifdef __IPHONE_13_0
154-
if (@available(iOS 13.0, *)) {
155-
self.thumbView.layer.cornerCurve = kCACornerCurveContinuous;
156-
}
157-
#endif
158149
[self.trackView addSubview:self.thumbView];
159150

160151
// Create list for managing each item
@@ -1272,15 +1263,25 @@ - (void)setCornerRadius:(CGFloat)cornerRadius {
12721263
[self _updateCornerRadius];
12731264
}
12741265

1266+
- (BOOL)_isCapsuleShape {
1267+
return _cornerRadius == TOSegmentendControlCapsuleCornerRadius;
1268+
}
1269+
12751270
- (CGFloat)_cornerRadiusValue {
1276-
const BOOL isCapsuleShape = _cornerRadius == TOSegmentendControlCapsuleCornerRadius;
1277-
return isCapsuleShape ? CGRectGetHeight(self.trackView.frame) / 2.0f : _cornerRadius;
1271+
return [self _isCapsuleShape] ? CGRectGetHeight(self.trackView.frame) / 2.0f : _cornerRadius;
12781272
}
12791273

12801274
- (void)_updateCornerRadius {
12811275
const CGFloat cornerRadius = [self _cornerRadiusValue];
12821276
self.trackView.layer.cornerRadius = cornerRadius;
1283-
self.thumbView.layer.cornerRadius = (cornerRadius - _thumbInset) + 1.0f;
1277+
self.thumbView.layer.cornerRadius = (cornerRadius - _thumbInset);
1278+
1279+
#ifdef __IPHONE_13_0
1280+
if (@available(iOS 13.0, *)) {
1281+
self.thumbView.layer.cornerCurve = kCACornerCurveContinuous;
1282+
self.trackView.layer.cornerCurve = kCACornerCurveContinuous;
1283+
}
1284+
#endif
12841285
}
12851286

12861287
// -----------------------------------------------

0 commit comments

Comments
 (0)