IBDesignable - custom button image displaying wrong color in IB (and at runtime)
| Originator: | openradar.rond | ||
| Number: | rdar://20200040 | 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 setImage: programmatically … the image is displayed with the TINT color (both in IB and at runtime). [This is the tintColor inherited from UIView — even though the image does NOT have its .renderMode property set to Template.]
Workaround:
If the ‘image’ property is set manually in IB, then cleared, the image color returns to normal. (This might be temporary.)
Sample code, from subclass "CustomButton : UIButton”:
IB_DESIGNABLE
@interface CustomButton ()
@property (nonatomic, strong) IBInspectable NSString *buttonStyle;
@end
-(void)setButtonStyle:(NSString *)styleName {
if ([styleName isEqualToString:@“play"]) {
UIImage *foregroundImage = [UIImage imageNamed:(@“icon-play")
inBundle:[NSBundle bundleForClass:[self class]]
compatibleWithTraitCollection:nil];
[self setImage:foregroundImage forState:UIControlStateNormal];
}
}
Expected behavior:
The image should show in its true color — just as it does when the same property is set manually in IB [see screenshots].
Attachments:
'button-image-color1a.png' and 'button-image-color1b.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!