What is the best way to customize the look of UIButtons in an app? I am working on an app where we programatically update UIButtons to look the way we want. Most of the buttons are created in Interface Builder and we want to execute our customizeButton-method on them in an efficient way. I only see two ways of achieving this:
customizeButton for each button.
Problem: way too much hazzleinitWithCoder: call customizeButton. Then use this class for buttons in IB.
Problem: allthough this works for buttons created in IB and requires less boilerplate code than point 1, I have read all the warnings against subclassing UIButton because of their class cluster.Clearly there must be some better way, what is point 3?
Have a look at UIAppearance. It is available since iOS 5 and is especially for customizing the standard UI elements.
For ever class that is customizable is a class method called +appearance: and you can use it like this.
[[UIButton appearance] setBackgroundColor:[UIColor redColor]];
Every button will have now a red background color.
To get started have a look at Ray Wenderlichs Tutorial User Interface Customization in iOS 5 and/or session 114 - Customizing the Appearance of UIKit Controls of the WWDC11 videos.
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