UIButton does not account for title or image edge insets in intrinsic content size
| Originator: | joeldparsons | ||
| Number: | rdar://18348992 | Date Originated: | 16-Sep-2014 |
| Status: | Open | Resolved: | |
| Product: | iOS | Product Version: | 8.0 GM |
| Classification: | Bug | Reproducible: | Always |
Summary: When designing a UIButton in interface builder you can set insets on the content in a UIButton to make a gap between the imageView and the the titleLabel. The render in IB is what I would expect but at runtime the calculation for intrinsicContentSize for UIButton does not take the edge insets for the titleLabel or the imageView into account and therefore breaks the layout. Steps to Reproduce: Create UIButton Add image to imageView Add text for titleLabel add content inset to the button add content inset to the text on the left to give space between image and text run app Expected Results: Button renders like in IB (see attached screenshot) Actual Results: text is truncated as button is incorrectly sized by auto layout at runtime (see attached screenshot from device running iOS 8 GM) Version: iOS 8 GM, Xcode 6 GM Notes: Configuration: iPhone simulator, iPhone 5s Attachments: 'Broken Buttons.zip', 'Screen Shot 2014-09-16 at 11.47.07.png' and 'IMG_1244.PNG' were successfully uploaded.
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!
Can be fixed in subclass:
`
- (CGSize)intrinsicContentSize { return CGSizeMake(super.intrinsicContentSize.width + (self.contentEdgeInsets.left + self.contentEdgeInsets.right) + (self.titleEdgeInsets.left + self.titleEdgeInsets.right) + (self.imageEdgeInsets.left + self.imageEdgeInsets.right), super.intrinsicContentSize.height + (self.contentEdgeInsets.top + self.contentEdgeInsets.bottom) + (self.titleEdgeInsets.top + self.titleEdgeInsets.bottom) + (self.imageEdgeInsets.top + self.imageEdgeInsets.bottom)); } `