How to change font of UIButton with Swift

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

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

However .font is deprecated and I'm not sure how to change the font otherwise.

Any suggestions?


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.


For Swift 3.0:

button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)

where "boldSystemFont" and "16" can be replaced with your custom font and size.