IBDesignable - custom button title not displaying in IB
| Originator: | openradar.rond | ||
| Number: | rdar://20200593 | Date Originated: | 3/17/15 |
| Status: | Open | Resolved: | |
| Product: | Xcode | Product Version: | 6.1.1; 6.3b3 |
| Classification: | Developer Tools | Reproducible: | Always |
Summary:
In an IBDesignable subclass of UIButton, when calling setTitle: programmatically ... the title shows up *blank* in IB — UNLESS the default value (e.g., “Button”) is first DELETED from the corresponding field in IB. (The customized title text does show up properly at runtime.)
Sample code:
@interface CustomButton : UIButton
@end
IB_DESIGNABLE
@interface CustomButton ()
@property (nonatomic, strong) IBInspectable NSString *buttonStyle;
@end
-(void)setButtonStyle:(NSString *)styleName {
if ([styleName isEqualToString:@"edit"]) {
[self setTitle:@"Foo" forState:UIControlStateNormal];
}
}
Steps to Reproduce:
In Interface Builder ...
- Add a “Button” from the Object library to a view controller’s view
- Change its Class to a custom subclass containing the IBInspectable code below
- In IB’s Attributes Inspector, change the Button Style to the string value referenced in the code
- Once IBDesignable updates, observe that the button title being set in code is missing in the canvas in IB.
… Now, delete the default title in IB (“Button”), and see that the programmatically-set title is now displayed.
[Note: The issue does not appear at app runtime.]
Expected Results:
IB should display the custom title set programmatically when the IBInspectable setter method is called, regardless of the value set in IB.
Version:
OS X 10.9.5, Xcode 6.1.1; OS X 10.10.2, Xcode 6.3b3
Attachments:
'button-title-1a.png' and 'button-title-1b.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!