您的位置:首页 > 产品设计 > UI/UE

iOS在UIButton中换行

2014-02-12 11:42 162 查看
在iOS6.0以上,可以设置

UIButton.titleLable.lineBreakMode = NSLineBreakByWordWrapping;

UIButton.titleLabel.text = @"This is \n two lines";


并使用'\n'进行换行。

但由于NSLineBreakMode是 NS_ENUM_AVAILABLE_IOS(6.0)的,也就是从iOS6.0起才开始支持的,所以,在iOS6.0以下,还是要自己定义一个UIButton来实现换行效果。

PS. 经过实际测试,在iOS5.0上直接对UIButton的text中加入‘\n'也可以实现换行效果。具体原因未知。

相关链接:http://stackoverflow.com/questions/604632/how-do-you-add-multi-line-text-to-a-uibutton

以下复制自stackoverflow.com:

To allow multiple line you can use:
button.titleLabel.lineBreakMode = UILineBreakModeWordWrap;


you'll probably also want to call
button.titleLabel.textAlignment = UITextAlignmentCenter;


then just call:
[button setTitle: @"Line1\nLine2" forState: UIControlStateNormal];


For iOS 6 use the following:
button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
button.titleLabel.textAlignment = NSTextAlignmentCenter;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UIButton iOS 移动开发