Skip to content

Commit 03c2c07

Browse files
authored
Merge pull request #59 from TimOliver/alert-fixes
Fixes to integrate better into TOAlertViewController
2 parents 7bb17e2 + b22204b commit 03c2c07

7 files changed

Lines changed: 446 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
x.y.z Release Notes (yyyy-MM-dd)
22
=============================================================
33

4+
2.1.0 Release Notes (2026-05-27)
5+
=============================================================
6+
7+
### Added
8+
9+
* Re-added the `minimumWidth` property, now including the horizontal `contentInset` padding, to help external layout systems size the button around its content.
10+
11+
### Fixed
12+
13+
* An issue where the title label could wrap onto two lines after `sizeToFit` was called against an already-narrow frame.
14+
415
2.0.0 Release Notes (2026-01-22)
516
=============================================================
617

TORoundedButton.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'TORoundedButton'
3-
s.version = '2.0.0'
3+
s.version = '2.1.0'
44
s.license = { :type => 'MIT', :file => 'LICENSE' }
55
s.summary = 'A high-performance button control with rounded corners for iOS.'
66
s.homepage = 'https://github.com/TimOliver/TORoundedButton'

TORoundedButton/TORoundedButton.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
134134
/// A callback handler triggered each time the button is tapped.
135135
@property (nonatomic, copy) void (^tappedHandler)(void);
136136

137+
/// The smallest width this button can be while still fitting its content on a single
138+
/// line, including the horizontal `contentInset` padding. Useful for external layout
139+
/// systems (such as alert controllers) sizing themselves around the button.
140+
@property (nonatomic, readonly) CGFloat minimumWidth;
141+
137142
/// Create a new instance of a button that can be further configured with either text or custom subviews.
138143
/// The size will be 288 points wide, and 50 tall by default.
139144
- (instancetype)init;

TORoundedButton/TORoundedButton.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ - (void)layoutSubviews {
292292

293293
// Lay out the title label
294294
if (!_titleLabel) { return; }
295+
// Seed the label with the available content width first; otherwise a stale,
296+
// too-narrow frame makes sizeToFit wrap the text onto multiple lines even
297+
// when there is plenty of horizontal room.
298+
CGRect labelFrame = _titleLabel.frame;
299+
labelFrame.size = contentBounds.size;
300+
_titleLabel.frame = labelFrame;
295301
[_titleLabel sizeToFit];
296302
_titleLabel.center = (CGPoint){
297303
.x = CGRectGetMidX(_contentView.bounds),
@@ -330,6 +336,13 @@ - (CGSize)sizeThatFits:(CGSize)size {
330336
return newSize;
331337
}
332338

339+
- (CGFloat)minimumWidth {
340+
// Measure at a large but finite size so the content lays out on a single line
341+
// without tripping Core Text overflow handling (which a literal CGFLOAT_MAX can,
342+
// once sizeThatFits: subtracts the horizontal padding from it).
343+
return [self sizeThatFits:(CGSize){1.0e6, 1.0e6}].width;
344+
}
345+
333346
#pragma mark - Interaction -
334347

335348
- (void)_didTouchDownInside {

TORoundedButtonExample.xcodeproj/xcshareddata/xcschemes/TORoundedButtonExample.xcscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
shouldUseLaunchSchemeArgsEnv = "YES">
29+
shouldUseLaunchSchemeArgsEnv = "YES"
30+
codeCoverageEnabled = "YES">
3031
<MacroExpansion>
3132
<BuildableReference
3233
BuildableIdentifier = "primary"

0 commit comments

Comments
 (0)