最佳答案
我有以下密码:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, 25, 25);
[[button layer] setCornerRadius:5.0f];
[[button layer] setMasksToBounds:YES];
[[button layer] setBackgroundColor:[[UIColor redColor] CGColor]];
[button.titleLabel setFrame:CGRectMake(0,0, 25, 25)];
[button setTitle:[NSString stringWithFormat:@"%@", [[topics objectAtIndex:indexPath.row] unread]] forState:UIControlStateNormal];
问题是,当文本中的字符串不长时,它会显示正确(1-2位)。然而,当它相当长(3 + + 数字) ,我只能看到一个红色按钮,里面没有文本。我要怎么调整?
我不这么认为:
[button.titleLabel setAdjustsFontSizeToFitWidth:YES];
能完成任务,对吧?