diff --git a/CHANGELOG.md b/CHANGELOG.md index 2043b85..e11a6dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,20 @@ x.y.z Release Notes (yyyy-MM-dd) ============================================================= -1.1.0 Release Notes (yyyy-MM-dd) +1.1.1 Release Notes (2019-06-21) +============================================================= + +### Enhancements + +* Added unit tests to check consistent initial behaviour. ([#22](https://github.com/TimOliver/TORoundedButton/pull/22)) +* Updated the documentation in the header to match expected default values. ([#22](https://github.com/TimOliver/TORoundedButton/pull/22)) + +### Fixed + +* A bug where the dynamic text size would not properly restore. ([#22](https://github.com/TimOliver/TORoundedButton/pull/22)) + + +1.1.0 Release Notes (2019-06-21) ============================================================= ### Enchancements diff --git a/TORoundedButton/TORoundedButton.h b/TORoundedButton/TORoundedButton.h index ca0dfb8..f7f65e8 100644 --- a/TORoundedButton/TORoundedButton.h +++ b/TORoundedButton/TORoundedButton.h @@ -42,7 +42,7 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl /** 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 0.5f) */ +/** 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) */ @@ -57,7 +57,7 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl /** 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 off with 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) */ diff --git a/TORoundedButton/TORoundedButton.m b/TORoundedButton/TORoundedButton.m index d3ff067..3c804e1 100644 --- a/TORoundedButton/TORoundedButton.m +++ b/TORoundedButton/TORoundedButton.m @@ -59,6 +59,7 @@ - (instancetype)initWithText:(NSString *)text if (self = [super initWithFrame:(CGRect){0,0, 288.0f, 50.0f}]) { [self roundedButtonCommonInit]; _titleLabel.text = text; + [_titleLabel sizeToFit]; } return self; @@ -113,8 +114,7 @@ - (void)roundedButtonCommonInit [self.containerView addSubview:self.backgroundView]; // Create the title label that will display the button text - UIFont *buttonFont = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; - buttonFont = [UIFont systemFontOfSize:buttonFont.pointSize weight:UIFontWeightBold]; + UIFont *buttonFont = [UIFont systemFontOfSize:17.0f weight:UIFontWeightBold]; if (@available(iOS 11.0, *)) { // Apply resizable button metrics to font UIFontMetrics *metrics = [[UIFontMetrics alloc] initForTextStyle:UIFontTextStyleBody]; @@ -128,7 +128,6 @@ - (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 @@ -145,6 +144,7 @@ - (void)layoutSubviews [super layoutSubviews]; // Configure the button text + [self.titleLabel sizeToFit]; self.titleLabel.center = self.containerView.center; self.titleLabel.frame = CGRectIntegral(self.titleLabel.frame); } diff --git a/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m b/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m index e07e316..bf1a4aa 100644 --- a/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m +++ b/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m @@ -18,8 +18,43 @@ @implementation TORoundedButtonExampleTests - (void)testDefaultValues { TORoundedButton *button = [[TORoundedButton alloc] initWithText:@"Test"]; - XCTAssertNotNil(button); + XCTAssertEqual(button.text, @"Test"); + XCTAssertEqual(button.cornerRadius, 12.0f); + XCTAssertEqual(button.textColor, [UIColor whiteColor]); + XCTAssertEqual(button.tappedTextAlpha, 1.0f); + XCTAssertEqual(button.tappedTintColorBrightnessOffset, -0.1f); + XCTAssertEqual(button.tappedButtonScale, 0.97f); +} + +- (void)testMinimimumWidth +{ + TORoundedButton *button = [[TORoundedButton alloc] initWithText:@"Long Button Name"]; + + // Manually + UILabel *titleLabel = nil; + for (UIView *subview in button.subviews.firstObject.subviews) { + if ([subview isKindOfClass:[UILabel class]]) { + titleLabel = (UILabel *)subview; + break; + } + } + + XCTAssert(button.minimumWidth > 0.0f); + XCTAssertEqual(titleLabel.frame.size.width, button.minimumWidth); +} + +- (void)testButtonInteraction +{ + TORoundedButton *button = [[TORoundedButton alloc] initWithText:@"Long Button Name"]; + + XCTestExpectation *expectation = [[XCTestExpectation alloc] initWithDescription:@"Button was tapped"]; + button.tappedHandler = ^{ [expectation fulfill]; }; + + // Simulate button tap + [button sendActionsForControlEvents:UIControlEventTouchUpInside]; + + [self waitForExpectations:@[expectation] timeout:0.5f]; } @end