设置UIButton字体

17

我有以下代码来设置UIButton中的文本

[self.fullListButton_ setTitle:[NSString stringWithFormat:@"%d", [self.newsfeedItem_.newsfeedToSubjects count] - 3] forState:UIControlStateNormal];

问题是我似乎无法设置这个字体。我该如何设置?

1个回答

35

在较新的iOS版本中:

UIButton * myButton;
myButton.titleLabel.font = [UIFont systemFontOfSize: 12];

或者使用其他字体机制。

查看这里的UIButton部分:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/occ/instp/UIButton/titleLabel

以及这里的UIFont内容:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIFont_Class/Reference/Reference.html

在你的代码中:

self.fullListButton_.titleLabel.font = [UIFont systemFontOfSize: 12];
或者
self.fullListButton_.titleLabel.font = [UIFont fontWithName:@"Arial" size:12];

1
@xonegirlz:请确保您没有试图为 SystemButton 设置字体。 - chandu
2
应该是 "titleLabel",而不是 "titleLable"。 - Peter Johnson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接