嘗試使用iOS 8中的外觀設置所有按鈕的UIButton字體。Google搜索後,看起來Apple已經改變了從操作系統到操作系統的方式。在iOS 7中,這應該已經工作:iOS 8:UIButton外觀字體
UIButton.appearance().titleLabel?.font = UIFont.inviteButtonTitleFont()
但它似乎不工作了。任何人都知道你現在怎麼做?
嘗試使用iOS 8中的外觀設置所有按鈕的UIButton字體。Google搜索後,看起來Apple已經改變了從操作系統到操作系統的方式。在iOS 7中,這應該已經工作:iOS 8:UIButton外觀字體
UIButton.appearance().titleLabel?.font = UIFont.inviteButtonTitleFont()
但它似乎不工作了。任何人都知道你現在怎麼做?
字體的代理已從UILabel.appearance()中刪除,所以這就是爲什麼這不起作用的原因。
使用包含在方法上UILabel
UILabel.appearanceWhenContainedInInstancesOfClasses([UIButton.self]).font = UIFont.inviteButtonTitleFont()
這應該在iOS9工作時的模樣,看到iOS8上和7個解決方法這個答案appearanceWhenContainedIn in Swift。
(免責聲明,我沒有編譯代碼片段,所以要小心輸入錯誤)。
這對我來說不起作用,雖然它看起來應該是這樣 – jxmorris12
斯威夫特3:
let fontRegular = UIFont(name: "MyCustomRegularFont", size: 17.0)
UILabel.appearance(whenContainedInInstancesOf: [UIButton.self]).font = fontRegular
UIButton.appearance().tintColor = UIColor.red
您使用的操場上,或將您的UI元素在應用數據視圖的樹? –
我從我的應用程序運行代碼,而不是操場。 – RyJ
看,只有UILabel實現全局更改字體的代理,此代理才能正常工作。 –