diff --git a/TORoundedButton/TORoundedButton.h b/TORoundedButton/TORoundedButton.h index ed5b2fe..55630b5 100644 --- a/TORoundedButton/TORoundedButton.h +++ b/TORoundedButton/TORoundedButton.h @@ -25,7 +25,6 @@ NS_ASSUME_NONNULL_BEGIN @class TORoundedButton; -@class UICornerConfiguration; NS_SWIFT_NAME(RoundedButtonDelegate) @protocol TORoundedButtonDelegate @@ -42,9 +41,11 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl /// A delegate object that can receive tap events from this button. @property (nonatomic, weak) id delegate; +#ifdef __IPHONE_26_0 /// The corner-rounding behaviour of the button's boundaries. /// On iOS 26 and above, this is the `.capsule` preset by default. @property (nonatomic, strong, nullable) UICornerConfiguration *cornerConfiguration API_AVAILABLE(ios(26.0)); +#endif /// The radius of the corners of this button. /// (Default is 12.0f on iOS 18 and below. For iOS 26.0, changing this property will update `cornerConfiguration`.) diff --git a/TORoundedButton/TORoundedButton.m b/TORoundedButton/TORoundedButton.m index 96646d8..14e36b2 100644 --- a/TORoundedButton/TORoundedButton.m +++ b/TORoundedButton/TORoundedButton.m @@ -134,11 +134,15 @@ - (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT { [self addTarget:self action:@selector(_didDragInside) forControlEvents:UIControlEventTouchDragEnter]; // Set the corner radius depending on app version +#ifdef __IPHONE_26_0 if (@available(iOS 26.0, *)) { self.cornerConfiguration = [UICornerConfiguration capsuleConfiguration]; } else { _cornerRadius = (_cornerRadius > FLT_EPSILON) ?: 12.0f; } +#else + _cornerRadius = (_cornerRadius > FLT_EPSILON) ?: 12.0f; +#endif } - (void)_makeTitleLabelIfNeeded TOROUNDEDBUTTON_OBJC_DIRECT { @@ -518,15 +522,20 @@ - (void)setCornerRadius:(CGFloat)cornerRadius { _cornerRadius = cornerRadius; +#ifdef __IPHONE_26_0 if (@available(iOS 26.0, *)) { UICornerRadius *const radius = [UICornerRadius fixedRadius:_cornerRadius]; _backgroundView.cornerConfiguration = [UICornerConfiguration configurationWithUniformRadius:radius]; } else { _backgroundView.layer.cornerRadius = _cornerRadius; } +#else + _backgroundView.layer.cornerRadius = _cornerRadius; +#endif [self setNeedsLayout]; } +#ifdef __IPHONE_26_0 - (void)setCornerConfiguration:(UICornerConfiguration *)cornerConfiguration { _backgroundView.cornerConfiguration = cornerConfiguration; } @@ -534,6 +543,7 @@ - (void)setCornerConfiguration:(UICornerConfiguration *)cornerConfiguration { - (UICornerConfiguration *)cornerConfiguration { return _backgroundView.cornerConfiguration; } +#endif - (void)setIsTranslucent:(BOOL)isTranslucent { if (_isTranslucent == isTranslucent) { diff --git a/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m b/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m index a1b1bb0..6b4c6b7 100644 --- a/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m +++ b/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m @@ -26,11 +26,15 @@ - (void)testDefaultValues XCTAssertEqual(button.tappedTintColorBrightnessOffset, -0.15f); XCTAssertEqual(button.tappedButtonScale, 0.97f); +#ifdef __IPHONE_26_0 if (@available(iOS 26.0, *)) { XCTAssertNotNil(button.cornerConfiguration); } else { XCTAssertEqual(button.cornerRadius, 12.0f); } +#else + XCTAssertEqual(button.cornerRadius, 12.0f); +#endif } - (void)testButtonInteraction