You do not have access to the imageView background , but there is a fully working workaround:
EDIT : There is an even better workaround than what I originally posted. You can create a UIImage from any color and call -setBackgroundImage:forState.
See bradley's answer, here: https://stackoverflow.com/a/166778/
Original answer:
Instead of calling -setBackgroundImage:forState: create a new UIImageView and add it as a sub-item of the button.
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:img]; bgImageView.contentMode = UIViewContentModeScaleAspectFit; [bgImageView setFrame:CGRectMake(0, 0, videoButton.frame.size.width, videoButton.frame.size.height)]; bgImageView.tag = 99; [yourButton addSubview:bgImageView]; [yourButton bringSubviewToFront:yourButton.imageView];
- Image creation
- Set content mode and frame
- I also set a recognizable tag, so that when the screen rotates, I can easily find my own image in the button view and reset its frame
- Add it as a sub item to the button
- Provide a front image Note of the button on the front panel so that our custom image does not overlap it.
When you need to rotate the button, just find the View image by its tag and reset its frame:
UIImageView *bgImageView = (UIImageView *)[button viewWithTag:99]; [bgImageView setFrame:CGRectMake(0, 0, newWidth, newHeight)];
Zoltán Matók Jul 12 '14 at 8:01 a.m. 2014-07-12 20:01
source share