Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the font of a button in Swift

I know this question has been asked before, and the question seemed to be solved, but I have an issue that I can't seem to solve. I'm trying to change to font of a UIButton using

advanceButton.titleLabel!.font = UIFont (name: "ArchitectsDaughter", size: 17)

However, when I use this I get a compile message that

(AnyObject) ->() Does not have a member named 'titleLabel'

I've tried both the implicit, normal, and optional types for titleLabel but nothing will fix this. Can someone help me please? Thanks in advance!

like image 495
pbush25 Avatar asked Jan 28 '26 16:01

pbush25


2 Answers

Your advanceButton is not of type UIButton.

When you define advanceButton make sure it is of type UIButton.

like so,

var advanceButton : UIButton = UIButton()
advanceButton.titleLabel!.font = UIFont(name: "Times New Roman", size: 25)
like image 117
Nate4436271 Avatar answered Jan 31 '26 09:01

Nate4436271


That looks like you either have a method named advanceButton that is colliding with a variable named advanceButton, or instead of defining an @IBOutlet for your button you defined an @IBAction.

like image 38
Nate Cook Avatar answered Jan 31 '26 07:01

Nate Cook



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!