2015-04-06 46 views
1

尝试使用iOS 8中的外观设置所有按钮的UIButton字体。Google搜索后,看起来Apple已经改变了从操作系统到操作系统的方式。在iOS 7中,这应该已经工作:iOS 8:UIButton外观字体

UIButton.appearance().titleLabel?.font = UIFont.inviteButtonTitleFont() 

但它似乎不工作了。任何人都知道你现在怎么做?

+0

您使用的操场上,或将您的UI元素在应用数据视图的树? –

+0

我从我的应用程序运行代码,而不是操场。 – RyJ

+0

看,只有UILabel实现全局更改字体的代理,此代理才能正常工作。 –

回答

0

字体的代理已从UILabel.appearance()中删除,所以这就是为什么这不起作用的原因。

0

使用包含在方法上UILabel

UILabel.appearanceWhenContainedInInstancesOfClasses([UIButton.self]).font = UIFont.inviteButtonTitleFont() 

这应该在iOS9工作时的模样,看到iOS8上和7个解决方法这个答案appearanceWhenContainedIn in Swift

(免责声明,我没有编译代码片段,所以要小心输入错误)。

+0

这对我来说不起作用,虽然它看起来应该是这样 – jxmorris12

1

斯威夫特3:

let fontRegular = UIFont(name: "MyCustomRegularFont", size: 17.0) 
UILabel.appearance(whenContainedInInstancesOf: [UIButton.self]).font = fontRegular 
UIButton.appearance().tintColor = UIColor.red