设置UIButton字体

xon*_*rlz 17 iphone objective-c ipad ios

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

[self.fullListButton_ setTitle:[NSString stringWithFormat:@"%d", [self.newsfeedItem_.newsfeedToSubjects count] - 3] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

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

tru*_*cks 35

在较新版本的iOS中:

UIButton * myButton;
myButton.titleLabel.font = [UIFont systemFontOfSize: 12];
Run Code Online (Sandbox Code Playgroud)

或任何其他字体机制.

在这里查看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];
Run Code Online (Sandbox Code Playgroud)

要么

self.fullListButton_.titleLabel.font = [UIFont fontWithName:@"Arial" size:12];
Run Code Online (Sandbox Code Playgroud)

  • 它将是"titleLabel",而不是"titleLable" (2认同)