无法换行以在UIButton上工作 [英] can't get word wrap to work on UIButton

查看:64
本文介绍了无法换行以在UIButton上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的UIButton并尝试进行自动换行,但它总是在一行中显示超出按钮大小的文本。

I have a simple UIButton and try to get word wrap but it always shows the text in one line exceeding the button size.

 NSString * text = NSLocalizedString(@"Start Loading",@"Start Loading");
_continueBtn.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
_continueBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
[_continueBtn setTitle:text forState:UIControlStateNormal];

在UI构建器中,当我在其中设置自动换行时,也会自动换行-仅在运行应用程序时文本显示在一行中。

Also in UI builder when I set word wrap there the text wraps - only when I run the app the text appears in one line.

我在这里错过了什么?

推荐答案

尝试:

_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];

对我来说很好:

这篇关于无法换行以在UIButton上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆