Reputation: 726
I am trying to change the button background image. This code is working fine with IOS 6/7. After I upgrade to IOS 7.1 suddenly it is stop working.
[monday setBackgroundImage:[UIImage imageNamed:@"toggleTopRight"] forState:UIControlStateNormal];
BWT: the image is ok, because this code is being called in view will appear and this ok there ... when i press on the button that need to change the setBackgroundImage it's not working.
Upvotes: 2
Views: 3516
Reputation: 731
For me it's the foreground image that covered the background image. So make your foreground image transparent then the background image will show. Setting background image actually works fine now.
Upvotes: 1
Reputation: 2349
I had the same problem. I finally found out that setting a button's (background) image doesn't work on iOS 7.1, if the button is disabled.
Not sure if this fixes your problem, but it was mine. Calling setNeedsLayout
didn't help in my case, unfortunately. What you can do as a workaround is either to override UIButton or to add a category that contains a method like the following to set an image:
- (void)setBackgroundImage:(UIImage *)img forButtonState:(UIControlState)state
BOOL shouldEnable = self.enabled;
self.enabled = YES;
[self setBackgroundImage:img forState:state];
self.enabled = shouldEnable;
}
Filed a bug report for this issue (16497031).
Upvotes: 1
Reputation: 902
This is a bug on 7.1 SDK and Xcode 5.1.
The workaround is to call [UIButton setNeedsLayout] after your changes.
That should do the trick.
Upvotes: 3