UIButton sizeToFit shows insets (instead of UIEdgeInsetsZero)
| Originator: | LZilber | ||
| Number: | rdar://21437476 | Date Originated: | 18/06/2015 |
| Status: | Fixed | Resolved: | iOS 9 GM (Build: 13A344) |
| Product: | iOS SDK | Product Version: | iOS 8.3 |
| Classification: | Reproducible: | Yes |
Summary:
When creating a UIButton programmatically with a title and no image, a call to sizeToFit adds top and bottom content insets to the button layout.
Steps to Reproduce:
1. Create a New Project
2. Add a UIButton subview programmatically in viewDidLoad, e.g. :
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:@"Tap Me" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
btn.backgroundColor = [UIColor darkGrayColor];
btn.titleLabel.backgroundColor = [UIColor blueColor];
[btn sizeToFit]; // Resize will set the width and height
[self.view addSubview:btn];
3. Run in Simulator
Expected Results:
The UIButton documentation should specify any sizing constraint applied when computing sizeThatFit. It seems understandable that a button "too small" would be poor user experience, hence maybe the SDK is enforcing a minimum height and width.
Actual Results:
Top and Bottom content edge insets are added.
The same behaviors occurs when explicitly setting the contentEdgeInsets property to 0. However it is possible to apply a single pixel inset (like btn.contentEdgeInsets = UIEdgeInsetsMake( 0.0, 0.0, 1.0, 0.0);)
Apple Developer Relations16-Sep-2015 09:51 PM
We believe this issue has been addressed. Please verify this issue with iOS 9 GM (Build: 13A344) and update your bug report at http://bugreport.apple.com/ with the results.
iOS 9 GM (Build: 13A344)
https://developer.apple.com/ios/download/
Posted Date: Sept. 16th, 2015
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!