减少按钮文字大小

时间:2013-12-16 08:00:12

标签: ios objective-c uibutton

我有UIButton setBackgroundImage:并使用setTitle:作为文字。但文字大小太大。如何减小文字大小。

 prevBtn = [UIButton buttonWithType:UIButtonTypeCustom];
 [prevBtn setBackgroundImage:[UIImage imageNamed:@"previous_iphone.png"] forState:UIControlStateNormal];
 [prevBtn addTarget:self 
                action:@selector(goPrev:)
      forControlEvents:UIControlEventTouchDown];
 [prevBtn setTitle:@"Previous" forState:UIControlStateNormal];
 prevBtn.frame = CGRectMake(2, 5, 85, 30);

4 个答案:

答案 0 :(得分:2)

尝试设置按钮的字体,如下所示:

float size = 14.0; //assign size any value you wish for the font size.
prevBtn.titleLabel.font = [UIFont systemFontOfSize:size];

答案 1 :(得分:1)

将您的代码更改为此。当它不符合最小字体大小10时,它会自动缩小文本大小:

 prevBtn = [UIButton buttonWithType:UIButtonTypeCustom];
 [prevBtn setBackgroundImage:[UIImage imageNamed:@"previous_iphone.png"] forState:UIControlStateNormal];
 [prevBtn addTarget:self 
                action:@selector(goPrev:)
      forControlEvents:UIControlEventTouchDown];
 [prevBtn setTitle:@"Previous" forState:UIControlStateNormal];
 prevBtn.titleLabel.adjustsFontSizeToFitWidth = TRUE;
 prevBtn.titleLabel.minimumFontSize = 10;
 prevBtn.frame = CGRectMake(2, 5, 85, 30);

答案 2 :(得分:1)

[prevButton.titleLabel setFont: [UIFont systemFontOfSize: 13.0]];

答案 3 :(得分:1)

[prevBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];