开发者

changing font size of UIButton

开发者 https://www.devze.com 2023-03-06 17:17 出处:网络
I have a UIButton which displays a text, with the following code: [button setTitle:@\"Join this group\" forState:UIControlStateNormal];

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开发者_JAVA百科 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消