Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing font size of UIButton

Tags:

I have a UIButton which displays a text, with the following code:

 [button setTitle:@"Join this group" forState:UIControlStateNormal];

however, how do I change the font size for this? I tried

button.titleLabel.font = [UIFont fontWithName:@"Arial-MT" size:8.0];

but I think it's a totally different thing. Or at least how do I make the text to adjust to the size of the button frame. Should I just use textLabel.text instead?

like image 237
aherlambang Avatar asked May 18 '11 21:05

aherlambang


People also ask

How do I change font size in 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 font size on labels in Swift?

Change Font And Size Of UILabel In StoryboardXIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.


1 Answers

The reason that the code you're posting isn't working is probably because Arial isn't present in iOS. You can change the properties of a UIButton's titleLabel just like any other instance of UILabel. Read about that here.

So, you can change the font size with something like:

button.titleLabel.font = [UIFont systemFontOfSize:14.0];

You can choose a font by name, but not all fonts are available on iOS. Here's a list of ones that are.

like image 133
CharlieMezak Avatar answered Sep 21 '22 12:09

CharlieMezak