Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TORoundedButton/TORoundedButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
NS_ASSUME_NONNULL_BEGIN

@class TORoundedButton;
@class UICornerConfiguration;

NS_SWIFT_NAME(RoundedButtonDelegate)
@protocol TORoundedButtonDelegate <NSObject>
Expand All @@ -42,9 +41,11 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
/// A delegate object that can receive tap events from this button.
@property (nonatomic, weak) id<TORoundedButtonDelegate> 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`.)
Expand Down
10 changes: 10 additions & 0 deletions TORoundedButton/TORoundedButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -518,22 +522,28 @@ - (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;
}

- (UICornerConfiguration *)cornerConfiguration {
return _backgroundView.cornerConfiguration;
}
#endif

- (void)setIsTranslucent:(BOOL)isTranslucent {
if (_isTranslucent == isTranslucent) {
Expand Down
4 changes: 4 additions & 0 deletions TORoundedButtonExampleTests/TORoundedButtonExampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down