我有一个简单的 UIButton 并尝试自动换行,但它总是在一行中显示超过按钮大小的文本。
NSString * text = NSLocalizedString(@"Start Loading",@"Start Loading");
_continueBtn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
_continueBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
[_continueBtn setTitle:text forState:UIControlStateNormal];
同样在 UI builder 中,当我在那里设置自动换行时,文本会自动换行 - 只有当我运行该应用程序时,文本才会显示在一行中。
我在这里错过了什么?
最佳答案
尝试:
_continueBtn.titleLabel.numberOfLines = 0;
我试过下一个代码:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(20, 20, 70, 50);
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
button.titleLabel.textAlignment = NSTextAlignmentCenter;
[button setTitle:@"start loading"
forState:UIControlStateNormal];
[self.view addSubview:button];
它对我很有用:
关于cocoa-touch - 无法让自动换行在 UIButton 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15428796/