iphone - 更改 UIButton 的字体大小

标签 iphone objective-c

我有一个显示文本的 UIButton,代码如下:

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

但是,我该如何更改字体大小呢? 我试过了

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

但我认为这是完全不同的事情。 或者至少如何使文本适应按钮框架的大小。 我应该改用 textLabel.text 吗?

最佳答案

您发布的代码无法正常工作的原因可能是因为 iOS 中不存在 Arial。您可以像更改 UILabel 的任何其他实例一样更改 UIButtontitleLabel 的属性。读一读 here .

因此,您可以通过以下方式更改字体大小:

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

您可以按名称选择字体,但并非所有字体都可在 iOS 上使用。 Here's的列表。

关于iphone - 更改 UIButton 的字体大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6051191/

相关文章:

ios - 弹出回 ViewController 时,UITableView 中的单元格保持突出显示

iphone - 想要在通知事件发生时播放我的声音文件,然后停止

ios - accessibilityElementDidBecomeFocused 没有被调用

ios - 如何正确登录到 spotify?

iphone - 如果被包装的文本中有一个长字符串,则 sizeWithFont 不会为 UITextView 提供正确的高度

ios - block block block ,用 __weak self

ios - 覆盖 UITextField getter-setter

iphone - UIMoviePlayerController ... 可以用吗?

objective-c - UIView动画VS核心动画

ios - UIButton - 带图标的引导文本