17

我有以下代码用于在 UIButton 中设置文本

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

问题是我似乎无法为此设置字体。我该怎么做?

4

1 回答 1

35

In the newer version of iOS:

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

Or any other font mechanism.

Look here for the UIButton portions:

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

And here for the UIFont stuff:

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

In your code:

self.fullListButton_.titleLabel.font = [UIFont systemFontOfSize: 12];

or

self.fullListButton_.titleLabel.font = [UIFont fontWithName:@"Arial" size:12];
于 2012-07-12T00:00:13.867 回答