I have four buttons that are going to be styled in the same way on the same scene (using Storyboard). This is simple styling that will require overriding a few of the property defaults, but seems needlessly repetitive to set this for each individual button. I was thinking I’d create a subclass, but a lot of the posts I’ve read (particularly on stackoverflow) warn against doing this for UIButton (and the attempts I’ve made haven’t been successful).
Just hoping to get a general pointer on what’s considered the best approach for this. Thanks for any advice.
If you are targeting only iOS 5, I strongly recommend watching Session 114 – Customizing the Appearance of UIKit Controlsdeveloper login required of the WWDC 2011 Session Videos.
It explains in detail App-wide styling.
I want to modify yujis idea: Use a category on UIButton to setup the button
.h.
.m
Now you can call
[aButton configureMyButtonStyle]Of course you can also parse in some parameters, to distinguish several style.
use: