本来似乎是一个很简单的问题,一般搜索结果都可以搞定这个简单的多行问题,但是在我的环境下还是费了一些周折:
* 常用的办法:设置label两个属性:
label.lineBreakMode = NSLineBreakByWordWrapping;
label.numberOfLines = 0;
该办法没有解决我的问题,仍然没有换行。
自己拖了一个项目试了试,可以搞定,那就是我的环境问题了,根据项目中的不同组件尝试了不同的关键词,终于发现了端倪
ref : http://stackoverflow.com/questions/12789013/ios-multi-line-uilabel-in-auto-layout
增加设置: [label setPreferredMaxLayoutWidth:200.0];
官方说明:This property affects the size of the label when layout constraints are applied to it. During layout, if the text extends beyond the width specified by this property, the additional text is flowed to one or more new lines, thereby increasing the height of the label.
理解:在autolayout环境下实现多行label需要将这个属性设定一下,当大于一行时进行自动分行。