diff --git a/TORoundedButton/TORoundedButton.h b/TORoundedButton/TORoundedButton.h index f129257..9f312de 100644 --- a/TORoundedButton/TORoundedButton.h +++ b/TORoundedButton/TORoundedButton.h @@ -1,7 +1,7 @@ // // TORoundedButton.h // -// Copyright 2019-2023 Timothy Oliver. All rights reserved. +// Copyright 2019 Timothy Oliver. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to @@ -27,46 +27,46 @@ NS_ASSUME_NONNULL_BEGIN NS_SWIFT_NAME(RoundedButton) IB_DESIGNABLE @interface TORoundedButton : UIControl -/// The text that is displayed in center of the button (Default is "Button"). +/** The text that is displayed in center of the button (Default is "Button") */ @property (nonatomic, copy) IBInspectable NSString *text; -/// The attributed string used in the label of this button. See `UILabel.attributedText` documentation for full details (Default is nil). +/** The attributed string used in the label of this button. See `UILabel.attributedText` documentation for full details (Default is nil) */ @property (nonatomic, copy, nullable) NSAttributedString *attributedText; -/// The radius of the corners of this button (Default is 12.0f). +/** The radius of the corners of this button (Default is 12.0f) */ @property (nonatomic, assign) IBInspectable CGFloat cornerRadius; -/// The color of the text in this button (Default is white). +/** The color of the text in this button (Default is white) */ @property (nonatomic, strong) IBInspectable UIColor *textColor; -/// When tapped, the level of transparency that the text label animates to. (Defaults to off with 1.0f). +/** When tapped, the level of transparency that the text label animates to. (Defaults to off with 1.0f) */ @property (nonatomic, assign) IBInspectable CGFloat tappedTextAlpha; -/// The font of the text in the button (Default is size UIFontTextStyleBody with bold). +/** The font of the text in the button (Default is size UIFontTextStyleBody with bold) */ @property (nonatomic, strong) UIFont *textFont; -/// Because IB cannot handle fonts, this can alternatively be used to set the font size. (Default is off with 0.0). +/** Because IB cannot handle fonts, this can alternatively be used to set the font size. (Default is off with 0.0) */ @property (nonatomic, assign) IBInspectable CGFloat textPointSize; -/// Taking the default button background color apply a brightness offset for the tapped color (Default is -0.1f. Set 0.0 for off). +/** Taking the default button background color apply a brightness offset for the tapped color (Default is -0.1f. Set 0.0 for off) */ @property (nonatomic, assign) IBInspectable CGFloat tappedTintColorBrightnessOffset; -/// If desired, explicity set the background color of the button when tapped (Default is nil). +/** If desired, explicity set the background color of the button when tapped (Default is nil). */ @property (nonatomic, strong, nullable) IBInspectable UIColor *tappedTintColor; -/// When tapped, the scale by which the button shrinks during the animation (Default is 0.97f). +/** When tapped, the scale by which the button shrinks during the animation (Default is 0.97f) */ @property (nonatomic, assign) IBInspectable CGFloat tappedButtonScale; -/// The duration of the tapping cross-fade animation (Default is 0.4f). +/** The duration of the tapping cross-fade animation (Default is 0.4f) */ @property (nonatomic, assign) CGFloat tapAnimationDuration; -/// Given the current size of the text label, the smallest horizontal width in which this button can scale. +/** Given the current size of the text label, the smallest horizontal width in which this button can scale. */ @property (nonatomic, readonly) CGFloat minimumWidth; -/// A callback handler triggered each time the button is tapped. +/** A callback handler triggered each time the button is tapped. */ @property (nonatomic, copy) void (^tappedHandler)(void); -/// Create a new instance of a button with the provided text shown in the center. The size will be 288 points wide, and 50 tall. +/** Create a new instance with the supplied button text. The size will be 288 points wide, and 50 tall. */ - (instancetype)initWithText:(NSString *)text; @end diff --git a/TORoundedButton/TORoundedButton.m b/TORoundedButton/TORoundedButton.m index 8424dbe..4c0b120 100644 --- a/TORoundedButton/TORoundedButton.m +++ b/TORoundedButton/TORoundedButton.m @@ -1,7 +1,7 @@ // // TORoundedButton.m // -// Copyright 2019-2023 Timothy Oliver. All rights reserved. +// Copyright 2019 Timothy Oliver. All rights reserved. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to @@ -20,10 +20,27 @@ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR // IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -#define TOROUNDEDBUTTON_OBJC_DIRECT __attribute__((objc_direct)) - #import "TORoundedButton.h" +@interface TORoundedButton () + +/** Hold on to a global state for whether we are tapped or not because the state can change before blocks complete */ +@property (nonatomic, assign) BOOL isTapped; + +/** A container view that holds all of the content view and performs the clipping */ +@property (nonatomic, strong) UIView *containerView; + +/** The title label displaying the text in the center of the button */ +@property (nonatomic, strong) UILabel *titleLabel; + +/** An image view that displays the rounded box behind the button text */ +@property (nonatomic, strong) UIView *backgroundView; + +/** Checks whether the button is tapped, or the BG is transparent to return the correct label background*/ +@property (nonatomic, readonly) UIColor *labelBackgroundColor; + +@end + // -------------------------------------------------------------------- static inline BOOL TO_ROUNDED_BUTTON_FLOAT_IS_ZERO(CGFloat value) { @@ -36,26 +53,14 @@ static inline BOOL TO_ROUNDED_BUTTON_FLOATS_MATCH(CGFloat firstValue, CGFloat se // -------------------------------------------------------------------- -@implementation TORoundedButton { - /** Hold on to a global state for whether we are tapped - or not because the state can change before blocks complete. */ - BOOL _isTapped; - - /** A container view that holds all of the content view and performs the clipping. */ - UIView *_containerView; - - /** The title label displaying the text in the center of the button. */ - UILabel *_titleLabel; - - /** A background view that displays the rounded box behind the button text. */ - UIView *_backgroundView; -} +@implementation TORoundedButton #pragma mark - View Creation - -- (instancetype)initWithText:(NSString *)text { +- (instancetype)initWithText:(NSString *)text +{ if (self = [super initWithFrame:(CGRect){0,0, 288.0f, 50.0f}]) { - [self _roundedButtonCommonInit]; + [self roundedButtonCommonInit]; _titleLabel.text = text; [_titleLabel sizeToFit]; } @@ -63,23 +68,26 @@ - (instancetype)initWithText:(NSString *)text { return self; } -- (instancetype)initWithFrame:(CGRect)frame { +- (instancetype)initWithFrame:(CGRect)frame +{ if (self = [super initWithFrame:frame]) { - [self _roundedButtonCommonInit]; + [self roundedButtonCommonInit]; } return self; } -- (instancetype)initWithCoder:(NSCoder *)aDecoder { +- (instancetype)initWithCoder:(NSCoder *)aDecoder +{ if (self = [super initWithCoder:aDecoder]) { - [self _roundedButtonCommonInit]; + [self roundedButtonCommonInit]; } return self; } -- (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT { +- (void)roundedButtonCommonInit +{ // Default properties (Make sure they're not overriding IB) _cornerRadius = (_cornerRadius > FLT_EPSILON) ?: 12.0f; _tappedTextAlpha = (_tappedTextAlpha > FLT_EPSILON) ?: 1.0f; @@ -88,25 +96,25 @@ - (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT { _tappedTintColorBrightnessOffset = !TO_ROUNDED_BUTTON_FLOAT_IS_ZERO(_tappedTintColorBrightnessOffset) ?: -0.15f; // Set the tapped tint color if we've set to dynamically calculate it - [self _updateTappedTintColorForTintColor]; + [self updateTappedTintColorForTintColor]; // Create the container view that manages the image view and text - _containerView = [[UIView alloc] initWithFrame:self.bounds]; - _containerView.backgroundColor = [UIColor clearColor]; - _containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _containerView.userInteractionEnabled = NO; - _containerView.clipsToBounds = YES; - [self addSubview:_containerView]; + self.containerView = [[UIView alloc] initWithFrame:self.bounds]; + self.containerView.backgroundColor = [UIColor clearColor]; + self.containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.containerView.userInteractionEnabled = NO; + self.containerView.clipsToBounds = YES; + [self addSubview:self.containerView]; // Create the image view which will show the button background - _backgroundView = [[UIView alloc] initWithFrame:self.bounds]; - _backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _backgroundView.backgroundColor = self.tintColor; - _backgroundView.layer.cornerRadius = _cornerRadius; + self.backgroundView = [[UIView alloc] initWithFrame:self.bounds]; + self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + self.backgroundView.backgroundColor = self.tintColor; + self.backgroundView.layer.cornerRadius = _cornerRadius; #ifdef __IPHONE_13_0 - if (@available(iOS 13.0, *)) { _backgroundView.layer.cornerCurve = kCACornerCurveContinuous; } + if (@available(iOS 13.0, *)) { self.backgroundView.layer.cornerCurve = kCACornerCurveContinuous; } #endif - [_containerView addSubview:_backgroundView]; + [self.containerView addSubview:self.backgroundView]; // Create the title label that will display the button text UIFont *buttonFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightBold]; @@ -116,48 +124,52 @@ - (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT { buttonFont = [metrics scaledFontForFont:buttonFont]; } - _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; - _titleLabel.textAlignment = NSTextAlignmentCenter; - _titleLabel.textColor = [UIColor whiteColor]; - _titleLabel.font = buttonFont; - _titleLabel.adjustsFontForContentSizeCategory = YES; - _titleLabel.backgroundColor = [self _labelBackgroundColor]; - _titleLabel.text = @"Button"; - _titleLabel.numberOfLines = 0; - [_containerView addSubview:_titleLabel]; + self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; + self.titleLabel.textAlignment = NSTextAlignmentCenter; + self.titleLabel.textColor = [UIColor whiteColor]; + self.titleLabel.font = buttonFont; + self.titleLabel.adjustsFontForContentSizeCategory = YES; + self.titleLabel.backgroundColor = self.labelBackgroundColor; + self.titleLabel.text = @"Button"; + self.titleLabel.numberOfLines = 0; + [self.containerView addSubview:self.titleLabel]; // Create action events for all possible interactions with this control - [self addTarget:self action:@selector(_didTouchDownInside) forControlEvents:UIControlEventTouchDown|UIControlEventTouchDownRepeat]; - [self addTarget:self action:@selector(_didTouchUpInside) forControlEvents:UIControlEventTouchUpInside]; - [self addTarget:self action:@selector(_didDragOutside) forControlEvents:UIControlEventTouchDragExit|UIControlEventTouchCancel]; - [self addTarget:self action:@selector(_didDragInside) forControlEvents:UIControlEventTouchDragEnter]; + [self addTarget:self action:@selector(didTouchDownInside) forControlEvents:UIControlEventTouchDown|UIControlEventTouchDownRepeat]; + [self addTarget:self action:@selector(didTouchUpInside) forControlEvents:UIControlEventTouchUpInside]; + [self addTarget:self action:@selector(didDragOutside) forControlEvents:UIControlEventTouchDragExit|UIControlEventTouchCancel]; + [self addTarget:self action:@selector(didDragInside) forControlEvents:UIControlEventTouchDragEnter]; } #pragma mark - View Displaying - -- (void)layoutSubviews { +- (void)layoutSubviews +{ [super layoutSubviews]; // Configure the button text - [_titleLabel sizeToFit]; - _titleLabel.center = _containerView.center; - _titleLabel.frame = CGRectIntegral(_titleLabel.frame); + [self.titleLabel sizeToFit]; + self.titleLabel.center = self.containerView.center; + self.titleLabel.frame = CGRectIntegral(self.titleLabel.frame); } -- (void)tintColorDidChange { +- (void)tintColorDidChange +{ [super tintColorDidChange]; - _titleLabel.backgroundColor = [self _labelBackgroundColor]; - _backgroundView.backgroundColor = self.tintColor; + self.titleLabel.backgroundColor = self.labelBackgroundColor; + self.backgroundView.backgroundColor = self.tintColor; [self setNeedsLayout]; } -- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection { +- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection +{ [super traitCollectionDidChange:previousTraitCollection]; [self setNeedsLayout]; - [self _updateTappedTintColorForTintColor]; + [self updateTappedTintColorForTintColor]; } -- (void)_updateTappedTintColorForTintColor TOROUNDEDBUTTON_OBJC_DIRECT { +- (void)updateTappedTintColorForTintColor +{ if (TO_ROUNDED_BUTTON_FLOAT_IS_ZERO(_tappedTintColorBrightnessOffset)) { return; } @@ -167,13 +179,14 @@ - (void)_updateTappedTintColorForTintColor TOROUNDEDBUTTON_OBJC_DIRECT { tintColor = [tintColor resolvedColorWithTraitCollection:self.traitCollection]; } - _tappedTintColor = [self _brightnessAdjustedColorWithColor:tintColor - amount:_tappedTintColorBrightnessOffset]; + _tappedTintColor = [[self class] brightnessAdjustedColorWithColor:tintColor + amount:_tappedTintColorBrightnessOffset]; } -- (UIColor *)_labelBackgroundColor TOROUNDEDBUTTON_OBJC_DIRECT { +- (UIColor *)labelBackgroundColor +{ // Always return clear if tapped - if (_isTapped) { return [UIColor clearColor]; } + if (self.isTapped) { return [UIColor clearColor]; } // Return clear if the tint color isn't opaque BOOL isClear = CGColorGetAlpha(self.tintColor.CGColor) < (1.0f - FLT_EPSILON); @@ -182,22 +195,24 @@ - (UIColor *)_labelBackgroundColor TOROUNDEDBUTTON_OBJC_DIRECT { #pragma mark - Interaction - -- (void)_didTouchDownInside { - _isTapped = YES; - +- (void)didTouchDownInside +{ + self.isTapped = YES; + // The user touched their finger down into the button bounds - [self _setLabelAlphaTappedAnimated:NO]; - [self _setBackgroundColorTappedAnimated:YES]; - [self _setButtonScaledTappedAnimated:YES]; + [self setLabelAlphaTappedAnimated:NO]; + [self setBackgroundColorTappedAnimated:YES]; + [self setButtonScaledTappedAnimated:YES]; } -- (void)_didTouchUpInside { - _isTapped = NO; - +- (void)didTouchUpInside +{ + self.isTapped = NO; + // The user lifted their finger up from inside the button bounds - [self _setLabelAlphaTappedAnimated:YES]; - [self _setBackgroundColorTappedAnimated:YES]; - [self _setButtonScaledTappedAnimated:YES]; + [self setLabelAlphaTappedAnimated:YES]; + [self setBackgroundColorTappedAnimated:YES]; + [self setButtonScaledTappedAnimated:YES]; // Send the semantic button action for apps relying on this action [self sendActionsForControlEvents:UIControlEventPrimaryActionTriggered]; @@ -206,38 +221,41 @@ - (void)_didTouchUpInside { if (self.tappedHandler) { self.tappedHandler(); } } -- (void)_didDragOutside { - _isTapped = NO; - +- (void)didDragOutside +{ + self.isTapped = NO; + // After tapping down, without releasing, the user dragged their finger outside the bounds - [self _setLabelAlphaTappedAnimated:YES]; - [self _setBackgroundColorTappedAnimated:YES]; - [self _setButtonScaledTappedAnimated:YES]; + [self setLabelAlphaTappedAnimated:YES]; + [self setBackgroundColorTappedAnimated:YES]; + [self setButtonScaledTappedAnimated:YES]; } -- (void)_didDragInside { - _isTapped = YES; - +- (void)didDragInside +{ + self.isTapped = YES; + // After dragging out, without releasing, they dragged back in - [self _setLabelAlphaTappedAnimated:YES]; - [self _setBackgroundColorTappedAnimated:YES]; - [self _setButtonScaledTappedAnimated:YES]; + [self setLabelAlphaTappedAnimated:YES]; + [self setBackgroundColorTappedAnimated:YES]; + [self setButtonScaledTappedAnimated:YES]; } #pragma mark - Animation - -- (void)_setBackgroundColorTappedAnimated:(BOOL)animated TOROUNDEDBUTTON_OBJC_DIRECT { +- (void)setBackgroundColorTappedAnimated:(BOOL)animated +{ if (!self.tappedTintColor) { return; } // Toggle the background color of the title label void (^updateTitleOpacity)(void) = ^{ - self->_titleLabel.backgroundColor = [self _labelBackgroundColor]; + self.titleLabel.backgroundColor = self.labelBackgroundColor; }; // ----------------------------------------------------- void (^animationBlock)(void) = ^{ - self->_backgroundView.backgroundColor = self->_isTapped ? self.tappedTintColor : self.tintColor; + self.backgroundView.backgroundColor = self.isTapped ? self.tappedTintColor : self.tintColor; }; void (^completionBlock)(BOOL) = ^(BOOL completed){ @@ -250,7 +268,7 @@ - (void)_setBackgroundColorTappedAnimated:(BOOL)animated TOROUNDEDBUTTON_OBJC_DI completionBlock(YES); } else { - _titleLabel.backgroundColor = [UIColor clearColor]; + self.titleLabel.backgroundColor = [UIColor clearColor]; [UIView animateWithDuration:self.tapAnimationDuration delay:0.0f usingSpringWithDamping:1.0f @@ -262,26 +280,27 @@ - (void)_setBackgroundColorTappedAnimated:(BOOL)animated TOROUNDEDBUTTON_OBJC_DI } -- (void)_setLabelAlphaTappedAnimated:(BOOL)animated TOROUNDEDBUTTON_OBJC_DIRECT { +- (void)setLabelAlphaTappedAnimated:(BOOL)animated +{ if (self.tappedTextAlpha > 1.0f - FLT_EPSILON) { return; } - CGFloat alpha = _isTapped ? self.tappedTextAlpha : 1.0f; + CGFloat alpha = self.isTapped ? self.tappedTextAlpha : 1.0f; // Animate the alpha value of the label void (^animationBlock)(void) = ^{ - self->_titleLabel.alpha = alpha; + self.titleLabel.alpha = alpha; }; // If we're not animating, just call the blocks manually if (!animated) { // Remove any animations in progress - [_titleLabel.layer removeAnimationForKey:@"opacity"]; + [self.titleLabel.layer removeAnimationForKey:@"opacity"]; animationBlock(); return; } // Set the title label to clear beforehand - _titleLabel.backgroundColor = [UIColor clearColor]; + self.titleLabel.backgroundColor = [UIColor clearColor]; // Animate the button alpha [UIView animateWithDuration:self.tapAnimationDuration @@ -293,14 +312,15 @@ - (void)_setLabelAlphaTappedAnimated:(BOOL)animated TOROUNDEDBUTTON_OBJC_DIRECT completion:nil]; } -- (void)_setButtonScaledTappedAnimated:(BOOL)animated TOROUNDEDBUTTON_OBJC_DIRECT { +- (void)setButtonScaledTappedAnimated:(BOOL)animated +{ if (self.tappedButtonScale < FLT_EPSILON) { return; } - CGFloat scale = _isTapped ? self.tappedButtonScale : 1.0f; + CGFloat scale = self.isTapped ? self.tappedButtonScale : 1.0f; // Animate the alpha value of the label void (^animationBlock)(void) = ^{ - self->_containerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, + self.containerView.transform = CGAffineTransformScale(CGAffineTransformIdentity, scale, scale); }; @@ -323,56 +343,66 @@ - (void)_setButtonScaledTappedAnimated:(BOOL)animated TOROUNDEDBUTTON_OBJC_DIREC #pragma mark - Public Accessors - -- (void)setAttributedText:(NSAttributedString *)attributedText { - _titleLabel.attributedText = attributedText; - [_titleLabel sizeToFit]; +- (void)setAttributedText:(NSAttributedString *)attributedText +{ + self.titleLabel.attributedText = attributedText; + [self.titleLabel sizeToFit]; [self setNeedsLayout]; } -- (NSAttributedString *)attributedText { return _titleLabel.attributedText; } +- (NSAttributedString *)attributedText +{ + return self.titleLabel.attributedText; +} -- (void)setText:(NSString *)text { - _titleLabel.text = text; - [_titleLabel sizeToFit]; +- (void)setText:(NSString *)text +{ + self.titleLabel.text = text; + [self.titleLabel sizeToFit]; [self setNeedsLayout]; } +- (NSString *)text { return self.titleLabel.text; } -- (NSString *)text { return _titleLabel.text; } - -- (void)setTextFont:(UIFont *)textFont { - _titleLabel.font = textFont; +- (void)setTextFont:(UIFont *)textFont +{ + self.titleLabel.font = textFont; self.textPointSize = 0.0f; // Reset the IB text point size back to disabled } -- (UIFont *)textFont { return _titleLabel.font; } +- (UIFont *)textFont { return self.titleLabel.font; } -- (void)setTextColor:(UIColor *)textColor { - _titleLabel.textColor = textColor; +- (void)setTextColor:(UIColor *)textColor +{ + self.titleLabel.textColor = textColor; } -- (UIColor *)textColor { return _titleLabel.textColor; } +- (UIColor *)textColor { return self.titleLabel.textColor; } -- (void)setTextPointSize:(CGFloat)textPointSize { +- (void)setTextPointSize:(CGFloat)textPointSize +{ if (_textPointSize == textPointSize) { return; } _textPointSize = textPointSize; - _titleLabel.font = [UIFont boldSystemFontOfSize:textPointSize]; + self.titleLabel.font = [UIFont boldSystemFontOfSize:textPointSize]; [self setNeedsLayout]; } -- (void)setTintColor:(UIColor *)tintColor { +- (void)setTintColor:(UIColor *)tintColor +{ [super setTintColor:tintColor]; - [self _updateTappedTintColorForTintColor]; - _backgroundView.backgroundColor = tintColor; - _titleLabel.backgroundColor = [self _labelBackgroundColor]; + [self updateTappedTintColorForTintColor]; + self.backgroundView.backgroundColor = tintColor; + self.titleLabel.backgroundColor = self.labelBackgroundColor; [self setNeedsLayout]; } -- (void)setTappedTintColor:(UIColor *)tappedTintColor { +- (void)setTappedTintColor:(UIColor *)tappedTintColor +{ if (_tappedTintColor == tappedTintColor) { return; } _tappedTintColor = tappedTintColor; _tappedTintColorBrightnessOffset = 0.0f; [self setNeedsLayout]; } -- (void)setTappedTintColorBrightnessOffset:(CGFloat)tappedTintColorBrightnessOffset { +- (void)setTappedTintColorBrightnessOffset:(CGFloat)tappedTintColorBrightnessOffset +{ if (TO_ROUNDED_BUTTON_FLOATS_MATCH(_tappedTintColorBrightnessOffset, tappedTintColorBrightnessOffset)) { @@ -380,33 +410,37 @@ - (void)setTappedTintColorBrightnessOffset:(CGFloat)tappedTintColorBrightnessOff } _tappedTintColorBrightnessOffset = tappedTintColorBrightnessOffset; - [self _updateTappedTintColorForTintColor]; + [self updateTappedTintColorForTintColor]; [self setNeedsLayout]; } -- (void)setCornerRadius:(CGFloat)cornerRadius { +- (void)setCornerRadius:(CGFloat)cornerRadius +{ // Make sure the corner radius doesn't match if (fabs(cornerRadius - _cornerRadius) < FLT_EPSILON) { return; } _cornerRadius = cornerRadius; - _backgroundView.layer.cornerRadius = _cornerRadius; + self.backgroundView.layer.cornerRadius = _cornerRadius; [self setNeedsLayout]; } -- (void)setEnabled:(BOOL)enabled { +- (void)setEnabled:(BOOL)enabled +{ [super setEnabled:enabled]; - _containerView.alpha = enabled ? 1 : 0.4; + self.containerView.alpha = enabled ? 1 : 0.4; } -- (CGFloat)minimumWidth { - return _titleLabel.frame.size.width; +- (CGFloat)minimumWidth +{ + return self.titleLabel.frame.size.width; } #pragma mark - Graphics Handling - -- (UIColor *)_brightnessAdjustedColorWithColor:(UIColor *)color amount:(CGFloat)amount TOROUNDEDBUTTON_OBJC_DIRECT { ++ (UIColor *)brightnessAdjustedColorWithColor:(UIColor *)color amount:(CGFloat)amount +{ if (!color) { return nil; } CGFloat h, s, b, a; diff --git a/TORoundedButtonExample.xcodeproj/project.pbxproj b/TORoundedButtonExample.xcodeproj/project.pbxproj index 2de098e..c006d84 100644 --- a/TORoundedButtonExample.xcodeproj/project.pbxproj +++ b/TORoundedButtonExample.xcodeproj/project.pbxproj @@ -3,11 +3,11 @@ archiveVersion = 1; classes = { }; - objectVersion = 54; + objectVersion = 52; objects = { /* Begin PBXBuildFile section */ - 220F9AB622784FD4001862A7 /* TORoundedButton.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 220F9AAE22784FD4001862A7 /* TORoundedButton.framework */; platformFilter = ios; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 220F9AB622784FD4001862A7 /* TORoundedButton.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 220F9AAE22784FD4001862A7 /* TORoundedButton.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 220F9ABC22784FF5001862A7 /* TORoundedButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 22700662226CA35D003492CB /* TORoundedButton.m */; platformFilter = ios; }; 2270063E226CA24D003492CB /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2270063D226CA24D003492CB /* AppDelegate.m */; }; 22700644226CA24D003492CB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 22700642226CA24D003492CB /* Main.storyboard */; }; @@ -50,7 +50,6 @@ 220F9ABE2278AA0B001862A7 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 220FC30822BC67E700B5C284 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 220FC30922BC67FE00B5C284 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = ""; }; - 221ACFC52AC939D700DE86FD /* TORoundedButtonExample.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = TORoundedButtonExample.entitlements; sourceTree = ""; }; 22700639226CA24D003492CB /* TORoundedButtonExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TORoundedButtonExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 2270063C226CA24D003492CB /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 2270063D226CA24D003492CB /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -129,7 +128,6 @@ 2270063B226CA24D003492CB /* TORoundedButtonExample */ = { isa = PBXGroup; children = ( - 221ACFC52AC939D700DE86FD /* TORoundedButtonExample.entitlements */, 2270063C226CA24D003492CB /* AppDelegate.h */, 2270063D226CA24D003492CB /* AppDelegate.m */, 22D23CC62276E73200EE65DD /* ViewController.h */, @@ -243,8 +241,7 @@ 22700631226CA24D003492CB /* Project object */ = { isa = PBXProject; attributes = { - BuildIndependentTargetsInParallel = YES; - LastUpgradeCheck = 1500; + LastUpgradeCheck = 1250; ORGANIZATIONNAME = "Tim Oliver"; TargetAttributes = { 220F9AAD22784FD4001862A7 = { @@ -376,15 +373,12 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_MODULE_VERIFIER = YES; INFOPLIST_FILE = "$(SRCROOT)/TORoundedButtonFramework/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; - MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++14"; PRODUCT_BUNDLE_IDENTIFIER = dev.tim.TORoundedButton; PRODUCT_NAME = TORoundedButton; SUPPORTS_MACCATALYST = NO; @@ -404,15 +398,12 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_MODULE_VERIFIER = YES; INFOPLIST_FILE = "$(SRCROOT)/TORoundedButtonFramework/Info.plist"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; - MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++14"; PRODUCT_BUNDLE_IDENTIFIER = dev.tim.TORoundedButton; PRODUCT_NAME = TORoundedButton; SUPPORTS_MACCATALYST = NO; @@ -459,7 +450,6 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; - ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -521,7 +511,6 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu11; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -543,7 +532,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = TORoundedButtonExample/TORoundedButtonExample.entitlements; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 6LF3GMKZAB; INFOPLIST_FILE = TORoundedButtonExample/Info.plist; @@ -555,8 +543,6 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.tim.TORoundedButtonExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; - SUPPORTS_MACCATALYST = YES; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -565,7 +551,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - CODE_SIGN_ENTITLEMENTS = TORoundedButtonExample/TORoundedButtonExample.entitlements; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = 6LF3GMKZAB; INFOPLIST_FILE = TORoundedButtonExample/Info.plist; @@ -577,8 +562,6 @@ ); PRODUCT_BUNDLE_IDENTIFIER = dev.tim.TORoundedButtonExample; PRODUCT_NAME = "$(TARGET_NAME)"; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; - SUPPORTS_MACCATALYST = YES; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; diff --git a/TORoundedButtonExample.xcodeproj/xcshareddata/xcschemes/TORoundedButtonExample.xcscheme b/TORoundedButtonExample.xcodeproj/xcshareddata/xcschemes/TORoundedButtonExample.xcscheme index 648ff15..27b7cae 100644 --- a/TORoundedButtonExample.xcodeproj/xcshareddata/xcschemes/TORoundedButtonExample.xcscheme +++ b/TORoundedButtonExample.xcodeproj/xcshareddata/xcschemes/TORoundedButtonExample.xcscheme @@ -1,6 +1,6 @@ - - - - diff --git a/TORoundedButtonExample/TORoundedButtonExample.entitlements b/TORoundedButtonExample/TORoundedButtonExample.entitlements deleted file mode 100644 index ee95ab7..0000000 --- a/TORoundedButtonExample/TORoundedButtonExample.entitlements +++ /dev/null @@ -1,10 +0,0 @@ - - - - - com.apple.security.app-sandbox - - com.apple.security.network.client - - -