I’m having an issue with UIButton’s image property. My asset catalog contains default images for Any / Any size class and images specific to Regular / Regular class. When I set UIButton’s image property in Interface Builder to “img_facebook” then the image is rendered incorrectly on iPad (image for Any / Any size is chosen instead of Regular / Regular one). But when I refresh it inside “traitCollectionDidChange:” method then the image is rendered correctly (see the attached code snippet).
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
{
[super traitCollectionDidChange:previousTraitCollection];
[_facebookButton setImage:[UIImage imageNamed:@"img_facebook"] forState:UIControlStateNormal];
}
It looks like IB creates an UIImage instance and assigns it to the property only once. It would make sense, but if I do the same with UIImage instead of UIButton everything works perfectly fine.
Has anyone experienced similar issue? Is it possible to fix that in IB or do I have to manually reset image in code?
I've just come up against a similar problem. It appears to be a bug with UIButton. I've checked the traitCollection property of my button (added to a regular view controller view via Interface Builder):
It's missing the expected size classes. Eg, the parent view traitCollection looks like this:
The easiest workaround is to modify your UIImageAsset to use the Device Specific option instead of the size classes:
And add iPhone and iPad specific images. That solved it for me (Xcode Beta 6.3)