From 2cbe80f6d732eefd380232d2a78fa46c696b1155 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 10:41:25 +0900 Subject: [PATCH 1/5] Added unit tests for confirming default values --- TORoundedButton/TORoundedButton.h | 4 ++-- TORoundedButtonExampleTests/TORoundedButtonExampleTests.m | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) 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/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m b/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m index e07e316..194f235 100644 --- a/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m +++ b/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m @@ -18,7 +18,12 @@ @implementation TORoundedButtonExampleTests - (void)testDefaultValues { TORoundedButton *button = [[TORoundedButton alloc] initWithText:@"Test"]; - + 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); XCTAssertNotNil(button); } From 0af58e8699bba25d60e7ef7e63c4e3e70ec6d7e8 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 11:05:32 +0900 Subject: [PATCH 2/5] Added sizeToFit in places to guarantee minimumWidth --- TORoundedButton/TORoundedButton.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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); } From 9b7226a143652e170b1ded37c0f1efb78fa9d4e5 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 11:05:41 +0900 Subject: [PATCH 3/5] Added more unit tests --- .../TORoundedButtonExampleTests.m | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m b/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m index 194f235..bf1a4aa 100644 --- a/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m +++ b/TORoundedButtonExampleTests/TORoundedButtonExampleTests.m @@ -18,13 +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); - XCTAssertNotNil(button); +} + +- (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 From 7d87b32cc2079434d0be7a44a3e73f3b26a813df Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 11:05:50 +0900 Subject: [PATCH 4/5] Updated CHANGELOG --- CHANGELOG.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2043b85..1051350 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. +* Updated the documentation in the header to match expected default values. + +### Fixed + +* A bug where the dynamic text size would not properly restore. + + +1.1.0 Release Notes (2019-06-21) ============================================================= ### Enchancements From f08012e4f85c090902d621106410d8615a43a5d1 Mon Sep 17 00:00:00 2001 From: Tim Oliver Date: Fri, 21 Jun 2019 11:07:44 +0900 Subject: [PATCH 5/5] Updated CHANGELOG --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1051350..e11a6dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,12 @@ x.y.z Release Notes (yyyy-MM-dd) ### Enhancements -* Added unit tests to check consistent initial behaviour. -* Updated the documentation in the header to match expected default values. +* 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. +* 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)