Using the following code to customize regular UIButtons also affects UIBarButtonItems and clear buttons in text fields.
[[UIButton appearance] setBackgroundImage:greenButtonImage forState:UIControlStateNormal];
I do not wish to customize the latter elements at all, only regular round rect buttons. I realize using appearanceWhenContainedIn: could be used to set a custom appearance for UIBarButtonItems and UITextField, but i wish for these buttons to remain standard. Subclassing is not an option here as it should not be required for such a simple task.
There is a similar question, but it does not address the issue. Why does -[[UIButton appearance] setBackgroundImage] affect the initial appearance of UIBarItem objects and how do you correct it?
One solution I've used before is to nil out the "backgroundImage" property for UIButtons contained inside of a UINavigationBar:
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil] setBackgroundImage:nil forState:UIControlStateNormal];
This should allow you to customize UIButtons in other cases, without touching the ones inside a UIBarButtonItem in the UINavigationBar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With