How to change font of UIButton with Swift

前端 未结 16 1297
故里飘歌
故里飘歌 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:35

    Use titleLabel instead. The font property is deprecated in iOS 3.0. It also does not work in Objective-C. titleLabel is label used for showing title on UIButton.

    myButton.titleLabel?.font =  UIFont(name: YourfontName, size: 20)
    

    However, while setting title text you should only use setTitle:forControlState:. Do not use titleLabel to set any text for title directly.

提交回复
热议问题