I am trying to change the font of a button on my view controller in my code because it is not working in the storyboard. For some reason, I keep trying but am unable to change the font of my button. Here's what my code looks like. The font name I chose is "Print Clearly" and I already set it up correctly so that it works on text fields, but am having trouble with buttons.
@IBOutlet weak var songSuggestButton: UIButton!
var theFont : UIFont = UIFont(name: "Print Clearly", size: 12)!
override func viewDidLoad() {
super.viewDidLoad()
songSuggestButton.titleLabel?.font = theFont
print(songSuggestButton.titleLabel?.font.fontDescriptor())
}
The print tells me the font is Print Clearly and size 12, but still shows up as the default font when I run my app.
Update: The second answer actually worked for me.
> Try this:
@IBOutlet weak var songSuggestButton: UIButton!
override func viewDidAppear() {
super.viewDidAppear(false)
songSuggestButton.titleLabel?.font = UIFont(name: "Print Clearly", size: 12)!
print(songSuggestButton.titleLabel?.font.fontDescriptor())
}
Strange how my custom fonts for buttons only work when initiated through this code. I also wanted to have different sizes of the font for my different view sizes, is there a way about doing this? Thanks.