设置UIButton字体

时间:2012-07-11 23:56:48

标签: iphone objective-c ios ipad

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

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

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

1 个答案:

答案 0 :(得分:34)

在较新版本的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];