diff --git a/CHANGELOG.md b/CHANGELOG.md index bbde644..2043b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ x.y.z Release Notes (yyyy-MM-dd) ### Enchancements +* Added `minimumWidth` property to help with guiding external layout. ([#21](https://github.com/TimOliver/TORoundedButton/pull/21)) * Refactored button from Core Animation labs chat at WWDC 2019. ([#20](https://github.com/TimOliver/TORoundedButton/pull/20)) * Increased corner radius default value to 12.0. ([#20](https://github.com/TimOliver/TORoundedButton/pull/20)) * Added lower alpha value when button is set to disabled. ([#15](https://github.com/TimOliver/TORoundedButton/pull/15)) diff --git a/TORoundedButton/TORoundedButton.h b/TORoundedButton/TORoundedButton.h index 0291e07..ca0dfb8 100644 --- a/TORoundedButton/TORoundedButton.h +++ b/TORoundedButton/TORoundedButton.h @@ -34,7 +34,7 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl @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) */ -@property (nonatomic, copy, nullable) NSAttributedString *attributedText; +@property (nonatomic, copy, nullable) NSAttributedString *attributedText; /** The radius of the corners of this button (Default is 12.0f) */ @property (nonatomic, assign) IBInspectable CGFloat cornerRadius; @@ -63,6 +63,9 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl /** 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. */ +@property (nonatomic, readonly) CGFloat minimumWidth; + /** A callback handler triggered each time the button is tapped. */ @property (nonatomic, copy) void (^tappedHandler)(void); diff --git a/TORoundedButton/TORoundedButton.m b/TORoundedButton/TORoundedButton.m index 59321c7..d3ff067 100644 --- a/TORoundedButton/TORoundedButton.m +++ b/TORoundedButton/TORoundedButton.m @@ -128,6 +128,7 @@ - (void)roundedButtonCommonInit self.titleLabel.adjustsFontForContentSizeCategory = YES; self.titleLabel.backgroundColor = self.tintColor; self.titleLabel.text = @"Button"; + [self.titleLabel sizeToFit]; [self.containerView addSubview:self.titleLabel]; // Create action events for all possible interactions with this control @@ -144,7 +145,6 @@ - (void)layoutSubviews [super layoutSubviews]; // Configure the button text - [self.titleLabel sizeToFit]; self.titleLabel.center = self.containerView.center; self.titleLabel.frame = CGRectIntegral(self.titleLabel.frame); } @@ -322,6 +322,8 @@ - (void)setButtonScaledTappedAnimated:(BOOL)animated - (void)setAttributedText:(NSAttributedString *)attributedText { self.titleLabel.attributedText = attributedText; + [self.titleLabel sizeToFit]; + [self setNeedsLayout]; } - (NSAttributedString *)attributedText @@ -332,6 +334,8 @@ - (NSAttributedString *)attributedText - (void)setText:(NSString *)text { self.titleLabel.text = text; + [self.titleLabel sizeToFit]; + [self setNeedsLayout]; } - (NSString *)text { return self.titleLabel.text; } @@ -404,6 +408,11 @@ - (void)setEnabled:(BOOL)enabled self.containerView.alpha = enabled ? 1 : 0.4; } +- (CGFloat)minimumWidth +{ + return self.titleLabel.frame.size.width; +} + #pragma mark - Graphics Handling - + (UIColor *)brightnessAdjustedColorWithColor:(UIColor *)color amount:(CGFloat)amount diff --git a/TORoundedButtonExample.xcodeproj/project.pbxproj b/TORoundedButtonExample.xcodeproj/project.pbxproj index d6d81a9..3653c40 100644 --- a/TORoundedButtonExample.xcodeproj/project.pbxproj +++ b/TORoundedButtonExample.xcodeproj/project.pbxproj @@ -55,6 +55,8 @@ /* Begin PBXFileReference section */ 220F9AAE22784FD4001862A7 /* TORoundedButton.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TORoundedButton.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 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 = ""; }; 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 = ""; }; @@ -110,11 +112,13 @@ 22700630226CA24D003492CB = { isa = PBXGroup; children = ( + 220FC30822BC67E700B5C284 /* README.md */, 22700660226CA322003492CB /* TORoundedButton */, 2270063B226CA24D003492CB /* TORoundedButtonExample */, 220F9ABD2278AA0B001862A7 /* TORoundedButtonFramework */, 22700654226CA24E003492CB /* TORoundedButtonExampleTests */, 2270063A226CA24D003492CB /* Products */, + 220FC30922BC67FE00B5C284 /* CHANGELOG.md */, ); sourceTree = ""; };