标题中包含两行文本的UIButton(numberOfLines = 2)
我正在尝试使UIButtontitleLabel中包含两行文本。这是我正在使用的代码: UIButton *titleButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, 100)]; titleButton.titleLabel.font = [UIFont boldSystemFontOfSize:24.0]; [titleButton setTitle:@"This text is very long and should get truncated at the end of the second line" forState:UIControlStateNormal]; titleButton.titleLabel.lineBreakMode = UILineBreakModeTailTruncation; titleButton.titleLabel.numberOfLines = 2; [self addSubview:titleButton]; 当我尝试此操作时,文本仅显示在一行上。似乎要获得多行文本的唯一方法UIButton.titleLabel是设置numberOfLines=0和使用UILineBreakModeWordWrap。但这不能保证文本恰好是两行。 UILabel但是,使用纯文本确实可以: UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 10, frame.size.width-100, …