Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the titleLabel.font property of a of a UIButton not working

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?

like image 520
gossainapps Avatar asked Oct 12 '13 22:10

gossainapps


People also ask

How do you change the font on UIButton?

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.

How do I change the button title color in Objective C?

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)


Video Answer


3 Answers

Using Xcode 13, I had to change Style property from Plain to Default on Interface Builder.

enter image description here

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)
like image 164
pableiros Avatar answered Oct 19 '22 09:10

pableiros


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];
like image 41
Niklas Avatar answered Oct 19 '22 11:10

Niklas


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.

like image 2
harthoo Avatar answered Oct 19 '22 10:10

harthoo