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
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions TORoundedButton/TORoundedButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand All @@ -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) */
Expand Down
6 changes: 3 additions & 3 deletions TORoundedButton/TORoundedButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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
Expand All @@ -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);
}
Expand Down
37 changes: 36 additions & 1 deletion TORoundedButtonExampleTests/TORoundedButtonExampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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