cocoa-touch - 无法让自动换行在 UIButton 上工作

标签 cocoa-touch uibutton

我有一个简单的 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];

它对我很有用:

screenshot

关于cocoa-touch - 无法让自动换行在 UIButton 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15428796/

相关文章:

ios - 如何实现 UICollectionView 中页面之间的间距?

iphone - 使用 EventKit 的 NSTimezone 问题

ios - UIbutton 在自定义 UITableViewCell 中释放

ios - 点击另一个按钮时隐藏 UIButton

ios - 通过更改背景颜色向用户显示他按下了按钮的简单方法?

ios - 调整文本的字体大小以适应 UIButton

ios - UITapGestureRecognizer 与 UISearchBar

iphone - 自动检查 iOS < 4.0 不支持的 API 调用?

uibutton - 带有图标的 iOS ipad Split View主按钮

ios - 如何将 UIButton 设置为转到上一个屏幕?