1
我正在使用Swift 2中的自定義鍵盤。我將爲所有標籤,按鈕和文本使用不同的字體。是否可以爲所有代碼設置一次字體值? 我與 `類KeyboardViewController工作:UIInputViewController {更改鍵盤的字體
}`
感謝。
我正在使用Swift 2中的自定義鍵盤。我將爲所有標籤,按鈕和文本使用不同的字體。是否可以爲所有代碼設置一次字體值? 我與 `類KeyboardViewController工作:UIInputViewController {更改鍵盤的字體
}`
感謝。
我爲我以前的答案道歉,試試這個:
override func viewDidLoad() {
super.viewDidLoad()
self.setFontFamily("FagoOfficeSans-Regular", forView: self.view!, andSubViews: true)
}
func setFontFamily(fontFamily: String, forView view: UIView, andSubViews isSubViews: Bool) {
if view.isKindOfClass(UILabel){
let lbl: UILabel = view as! UILabel
lbl.font = UIFont(name: fontFamily, size: lbl.font.pointSize)
}
if view.isKindOfClass(UIButton){
let lbl: UIButton = view as! UIButton
lbl.titleLabel?.font = UIFont(name: fontFamily, size: 12)!
}
if view.isKindOfClass(UITextField){
let lbl: UITextField = view as! UITextField
lbl.font = UIFont(name: fontFamily, size: 12)
}
if isSubViews {
for sview: UIView in view.subviews {
self.setFontFamily(fontFamily, forView: sview, andSubViews: true)
}
}
}
確定。我應該在哪裏放置?像UIInputViewController {AnyUIView.appearance()。font = UIFont(name:「yourFont」,size:yourSize)} –
嘗試在viewDidLoad() –
我試過像這樣:覆蓋func viewDidLoad(){ UIInputViewController.appearance ).font = UIFont(name:「font name」,size:font size)}}但它不起作用... –