I tried to set the font of UIButton
via appearance proxy. But it doesn't seem to work. This is what I tried.
UIButton.appearance().titleFont = UIFont(name: FONT_NAME_DEFAULT, size:20.0)
UIButton.appearance().titleLabel?.font = UIFont(name: FONT_NAME_DEFAULT, size:20.0)
How to set UIButton
font via appearance proxy in iOS 8 ?
EDIT: Found in vaberer's link: "I'm surprised that UIButton doesn't have any UI_APPEARANCE_SELECTOR properties, yet conforms to the UIAppearance protocol."
Had the same problem with a theme-able app.
1. Add this extension
2. Then setup the
UIButton
appearance prototype object3. Drop the theme setup in app delegate
If you're preloading stuff (
lazy var
VCs from storyboards) earlier, it may be better to instead of using app delegate setup the theme stuff in an override initializer like so:Barry's answer works great but the UIButton extension implementation is out of date - you need declare
var titleLabelFont
like:See full implementation here: http://blog.iseinc.biz/use-uiappearance-create-ios-app-themes
You can apply it to the label when contained in a button:
You are trying to set a font of
UILabel
insideUIButton
. SinceUILabel
is not tagged with UI_APPEARANCE_SELECTOR. You can't do it like this.Look at the list of the UIAppearance elements at: What properties can I set via an UIAppearance proxy?