Skip to content

Commit b3856c8

Browse files
committed
Added cornerConfiguration for iOS 26 support
1 parent 3f42156 commit b3856c8

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

TORoundedButton/TORoundedButton.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
NS_ASSUME_NONNULL_BEGIN
2626

2727
@class TORoundedButton;
28+
@class UICornerConfiguration;
2829

2930
NS_SWIFT_NAME(RoundedButtonDelegate)
3031
@protocol TORoundedButtonDelegate <NSObject>
@@ -41,8 +42,13 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
4142
/// A delegate object that can receive tap events from this button.
4243
@property (nonatomic, weak) id<TORoundedButtonDelegate> delegate;
4344

44-
/// The radius of the corners of this button (Default is 12.0f).
45-
@property (nonatomic, assign) IBInspectable CGFloat cornerRadius;
45+
/// The corner-rounding behaviour of the button's boundaries.
46+
/// On iOS 26 and above, this is the `.capsule` preset by default.
47+
@property (nonatomic, strong, nullable) UICornerConfiguration *cornerConfiguration API_AVAILABLE(ios(26.0));;
48+
49+
/// The radius of the corners of this button.
50+
/// (Default is 12.0f on iOS 18 and below. For iOS 26.0, use the `cornerConfiguration` property.)
51+
@property (nonatomic, assign) IBInspectable CGFloat cornerRadius API_DEPRECATED("Use `cornerConfiguration` instead.", ios(10.0, 18.0));;
4652

4753
/// The hosting container that manages all of the foreground views in this button.
4854
/// You can either add your custom views to this view by default, or you can set

TORoundedButton/TORoundedButton.m

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ @implementation TORoundedButton {
5555
#pragma mark - View Creation -
5656

5757
- (instancetype)init {
58-
if (self = [self initWithFrame:(CGRect){0,0, 288.0f, 50.0f}]) { }
58+
if (self = [self initWithFrame:(CGRect){0,0, 288.0f, 44.0f}]) { }
5959
return self;
6060
}
6161

@@ -86,7 +86,7 @@ - (instancetype)initWithContentView:(__kindof UIView *)contentView {
8686
}
8787

8888
- (instancetype)initWithText:(NSString *)text {
89-
if (self = [super initWithFrame:(CGRect){0,0, 288.0f, 50.0f}]) {
89+
if (self = [super initWithFrame:(CGRect){0,0, 288.0f, 44.0f}]) {
9090
_contentView = [UIView new];
9191
[self _roundedButtonCommonInit];
9292
[self _makeTitleLabelIfNeeded];
@@ -99,7 +99,6 @@ - (instancetype)initWithText:(NSString *)text {
9999

100100
- (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT {
101101
// Default properties (Make sure they're not overriding IB)
102-
_cornerRadius = (_cornerRadius > FLT_EPSILON) ?: 12.0f;
103102
_tappedTextAlpha = (_tappedTextAlpha > FLT_EPSILON) ?: 1.0f;
104103
_tapAnimationDuration = (_tapAnimationDuration > FLT_EPSILON) ?: 0.4f;
105104
_tappedButtonScale = (_tappedButtonScale > FLT_EPSILON) ?: 0.97f;
@@ -133,6 +132,13 @@ - (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT {
133132
[self addTarget:self action:@selector(_didTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
134133
[self addTarget:self action:@selector(_didDragOutside) forControlEvents:UIControlEventTouchDragExit|UIControlEventTouchCancel];
135134
[self addTarget:self action:@selector(_didDragInside) forControlEvents:UIControlEventTouchDragEnter];
135+
136+
// Set the corner radius depending on app version
137+
if (@available(iOS 26.0, *)) {
138+
self.cornerConfiguration = [UICornerConfiguration capsuleConfiguration];
139+
} else {
140+
_cornerRadius = (_cornerRadius > FLT_EPSILON) ?: 12.0f;
141+
}
136142
}
137143

138144
- (void)_makeTitleLabelIfNeeded TOROUNDEDBUTTON_OBJC_DIRECT {
@@ -166,7 +172,6 @@ - (UIView *)_makeBackgroundViewWithBlur:(BOOL)withBlur TOROUNDEDBUTTON_OBJC_DIRE
166172
}
167173
backgroundView.frame = self.bounds;
168174
backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
169-
backgroundView.layer.cornerRadius = _cornerRadius;
170175
#ifdef __IPHONE_13_0
171176
if (@available(iOS 13.0, *)) { backgroundView.layer.cornerCurve = kCACornerCurveContinuous; }
172177
#endif
@@ -511,12 +516,26 @@ - (void)setCornerRadius:(CGFloat)cornerRadius {
511516
if (fabs(cornerRadius - _cornerRadius) < FLT_EPSILON) {
512517
return;
513518
}
514-
519+
515520
_cornerRadius = cornerRadius;
516-
_backgroundView.layer.cornerRadius = _cornerRadius;
521+
522+
if (@available(iOS 26.0, *)) {
523+
UICornerRadius *const radius = [UICornerRadius fixedRadius:_cornerRadius];
524+
_backgroundView.cornerConfiguration = [UICornerConfiguration configurationWithUniformRadius:radius];
525+
} else {
526+
_backgroundView.layer.cornerRadius = _cornerRadius;
527+
}
517528
[self setNeedsLayout];
518529
}
519530

531+
- (void)setCornerConfiguration:(UICornerConfiguration *)cornerConfiguration {
532+
_backgroundView.cornerConfiguration = cornerConfiguration;
533+
}
534+
535+
- (UICornerConfiguration *)cornerConfiguration {
536+
return _backgroundView.cornerConfiguration;
537+
}
538+
520539
- (void)setIsTranslucent:(BOOL)isTranslucent {
521540
if (_isTranslucent == isTranslucent) {
522541
return;

0 commit comments

Comments
 (0)