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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion TORoundedButton/TORoundedButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 10 additions & 1 deletion TORoundedButton/TORoundedButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -322,6 +322,8 @@ - (void)setButtonScaledTappedAnimated:(BOOL)animated
- (void)setAttributedText:(NSAttributedString *)attributedText
{
self.titleLabel.attributedText = attributedText;
[self.titleLabel sizeToFit];
[self setNeedsLayout];
}

- (NSAttributedString *)attributedText
Expand All @@ -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; }

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions TORoundedButtonExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>"; };
220FC30822BC67E700B5C284 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
220FC30922BC67FE00B5C284 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
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 = "<group>"; };
2270063D226CA24D003492CB /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
};
Expand Down