From 2c5afb666ba97b6c84f33697badb71f382df7d89 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Thu, 20 Jun 2019 20:41:41 +0900 Subject: [PATCH 1/5] Added minimum width property to header --- TORoundedButton/TORoundedButton.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); From d21ee51f454ba3ba03bedb4afa6ab697fe84cbd8 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 10:25:27 +0900 Subject: [PATCH 2/5] Added minimum width and better sizing to button --- TORoundedButton/TORoundedButton.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 From c2f508fd795bae16419c68ae87655c81071c0106 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 10:25:38 +0900 Subject: [PATCH 3/5] Moved README and CHANGELOG to project --- TORoundedButtonExample.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) 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 = ""; }; From c4e8e7921feeccbe20eee2ba03eece97e30e9c15 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 10:25:45 +0900 Subject: [PATCH 4/5] Updated CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbde644..b488607 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. * 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)) From 55aa67327a744ae504c72165d1fc619450007a9d Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 10:31:59 +0900 Subject: [PATCH 5/5] Updated CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b488607..2043b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ x.y.z Release Notes (yyyy-MM-dd) ### Enchancements -* Added `minimumWidth` property to help with guiding external layout. +* 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))