如何在 iOS 8 中通过外观代理设置 UIButton 字体?
问题描述
我尝试通过外观代理设置 UIButton
的字体.但这似乎不起作用.这是我尝试过的.
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)
iOS 8中如何通过外观代理设置UIButton
字体?
How to set UIButton
font via appearance proxy in iOS 8 ?
编辑:在 vaberer 的 link:我很惊讶 UIButton 没有任何 UI_APPEARANCE_SELECTOR 属性,但符合 UIAppearance 协议."
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.
2.然后设置 UIButton
外观原型对象
2. Then setup the UIButton
appearance prototype object
3.在应用委托中删除主题设置
如果您早先预加载内容(lazy var
来自情节提要的 VC),最好不要使用应用委托设置主题内容,而是像这样在覆盖初始化程序中设置主题内容:
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:
这篇关于如何在 iOS 8 中通过外观代理设置 UIButton 字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!