diff --git a/TOSegmentedControl/TOSegmentedControl.m b/TOSegmentedControl/TOSegmentedControl.m index c7ca858..55e4ed9 100644 --- a/TOSegmentedControl/TOSegmentedControl.m +++ b/TOSegmentedControl/TOSegmentedControl.m @@ -140,21 +140,12 @@ - (void)commonInit { UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.trackView.layer.masksToBounds = YES; self.trackView.userInteractionEnabled = NO; -#ifdef __IPHONE_13_0 - if (@available(iOS 13.0, *)) { - self.trackView.layer.cornerCurve = kCACornerCurveContinuous; - } -#endif + [self addSubview:self.trackView]; // Create thumb view self.thumbView = [[UIView alloc] initWithFrame:CGRectMake(2.0f, 2.0f, 100.0f, 28.0f)]; self.thumbView.layer.shadowColor = [UIColor blackColor].CGColor; -#ifdef __IPHONE_13_0 - if (@available(iOS 13.0, *)) { - self.thumbView.layer.cornerCurve = kCACornerCurveContinuous; - } -#endif [self.trackView addSubview:self.thumbView]; // Create list for managing each item @@ -1272,15 +1263,30 @@ - (void)setCornerRadius:(CGFloat)cornerRadius { [self _updateCornerRadius]; } +- (BOOL)_isCapsuleShape { + return _cornerRadius == TOSegmentendControlCapsuleCornerRadius; +} + - (CGFloat)_cornerRadiusValue { - const BOOL isCapsuleShape = _cornerRadius == TOSegmentendControlCapsuleCornerRadius; - return isCapsuleShape ? CGRectGetHeight(self.trackView.frame) / 2.0f : _cornerRadius; + return [self _isCapsuleShape] ? CGRectGetHeight(self.trackView.frame) / 2.0f : _cornerRadius; } - (void)_updateCornerRadius { const CGFloat cornerRadius = [self _cornerRadiusValue]; - self.trackView.layer.cornerRadius = cornerRadius; - self.thumbView.layer.cornerRadius = (cornerRadius - _thumbInset) + 1.0f; + if (@available(iOS 26.0, *)) { + self.trackView.cornerConfiguration = [UICornerConfiguration configurationWithRadius:[UICornerRadius fixedRadius:cornerRadius]]; + self.thumbView.cornerConfiguration = [UICornerConfiguration configurationWithRadius:[UICornerRadius fixedRadius:cornerRadius - _thumbInset]]; + } else { + self.trackView.layer.cornerRadius = cornerRadius; + self.thumbView.layer.cornerRadius = (cornerRadius - _thumbInset); + + #ifdef __IPHONE_13_0 + if (@available(iOS 13.0, *)) { + self.thumbView.layer.cornerCurve = kCACornerCurveContinuous; + self.trackView.layer.cornerCurve = kCACornerCurveContinuous; + } + #endif + } } // ----------------------------------------------- @@ -1472,7 +1478,7 @@ - (void)setSelectedTextFont:(UIFont *)selectedTextFont { - (void)setThumbInset:(CGFloat)thumbInset { _thumbInset = thumbInset; - self.thumbView.layer.cornerRadius = ([self _cornerRadiusValue] - _thumbInset) + 1.0f; + self.thumbView.layer.cornerRadius = ([self _cornerRadiusValue] - _thumbInset); } // -----------------------------------------------