In currently working with iOS 7 and I an attempting to increase the font size of the titleLabel of my UIButton. I am doing it like this,
[[_centerButton titleLabel] setFont:[UIFont boldSystemFontOfSize:28.0]];
However this does not do anything. Every time I compile with a different size the font always stays the same. Even when I completely delete that line the font stays the same. Apparently it is sticking to the default size.
How can I increase the font size of my UIButton title?
To set a different font on UIButton programmatically you will need to create a new instance of UIFont object. The initializer of UIFont accepts two arguments: name and size. where the “GillSans-Italic” is a font name you want to set.
You can use your custom color by using RGB method: button. setTitleColor(UIColor(displayP3Red: 0.0/255.0, green: 180.0/255.0, blue: 2.0/255.0, alpha: 1.0), for: . normal)
Using Xcode 13
, I had to change Style
property from Plain
to Default
on Interface Builder
.
Then after set the title, I finally could change the font programmatically without a problem:
button.setTitle("The title", for: .normal)
button.titleLabel?.font = UIFont(name: "Montserrat-SemiBold", size: 15)
Have a look at the official UIButton class reference on https://developer.apple.com/library/ios/documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/occ/instp/UIButton/titleLabel
It says that you're actually able to set the font with your method:
button.titleLabel.font = [UIFont systemFontOfSize: 12];
Well I had the same problem, have you used interface builder? after I set the title property to Plain, it's working, very very weird.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With