简体   繁体   中英

changing font size of UIButton

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM