How to change font of UIButton with Swift

前端 未结 16 1290
故里飘歌
故里飘歌 2020-12-12 11:51

I am trying to change the font of a UIButton using Swift...

myButton.font = UIFont(name: \"...\", 10)

However .font is depreca

16条回答
  •  孤城傲影
    2020-12-12 12:15

    If you are setting AttributedString to the UIButton then you can do the below thing.

    let attributedText = NSAttributedString(string: "Hello", attributes: [NSAttributedStringKey.font: UIFont(name: "Calibri", size: 19)])
    okayButton.setAttributedTitle(attributedText, for: .normal)
    

提交回复
热议问题