How to change font of UIButton with Swift

前端 未结 16 1292
故里飘歌
故里飘歌 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条回答
  •  旧时难觅i
    2020-12-12 12:13

    we can use different types of system fonts like below

    myButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 17)
    myButton.titleLabel?.font = UIFont.italicSystemFont(ofSize:UIFont.smallSystemFontSize)
    myButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: UIFont.buttonFontSize)
    

    and your custom font like below

        myButton.titleLabel?.font = UIFont(name: "Helvetica", size:12)
    

提交回复
热议问题