Adjust height of UILabel dynamically using iOS storyboard

白昼怎懂夜的黑 提交于 2019-12-08 19:03:56

问题


I have a label, which has been created using iOS Storyboard layout.

Contents of label, however, are dynamic and can change during run time.

How do I make sure that label's height gets adjusted based on the content in the label.

I tried:

Setting number of lines to 0

Setting Editor -> Size to Fit Content.

But they don't work. Text in label gets printed only in single line, and as a result of that some of text doesn't appear on the screen.

Any help would be highly appreciated.


回答1:


Try this way

Your lable should be number of lines to 0

give height constraint to lable and select height constraint then set greater than equal , it will automatically adjust height based on content




回答2:


Please check your constraints. You can't set label's height constraint.If superview's height is fixed,you can't set top and bottom constraint at same time.Because it means you set the height constraint of label. So you can must fix label width and you can't fix label height.



来源:https://stackoverflow.com/questions/38471569/adjust-height-of-uilabel-dynamically-using-ios-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!