简体   繁体   English

iOS使标签包装内容像Android一样高度和宽度

[英]Ios make label wrap content both height and width like android

I'm new to ios how to make label as wrap content both width and height. 我是ios新手,如何使标签作为包裹内容的宽度和高度。 i have use following things too 我也用过以下东西

textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;

But i cant make label height and width as wrap content 但是我不能将标签的高度和宽度作为包装内容

So assuming you use Auto Layout, you can always use this line to make the label fit its content horizontally 因此,假设您使用自动版式,则始终可以使用此行使标签水平适应其内容

[textLabel setContentHuggingPriority:UILayoutPriorityRequired
                             forAxis:UILayoutConstraintAxisHorizontal];

If you are not using Auto Layout, try adding this after setting the font, font size and all other details. 如果您没有使用自动版式,请尝试在设置字体,字体大小和所有其他详细信息之后添加。

[textLabel sizeToFit]

Try adding: 尝试添加:

[textLabel sizeToFit];

after: 后:

textLabel.lineBreakMode = NSLineBreakByWordWrapping;
textLabel.numberOfLines = 0;

Also, if you are using "Auto" layout, then check your constraints are not conflicting. 另外,如果您使用的是“自动”布局,则请检查您的约束条件是否冲突。 Make sure if you have not provided "Fixed" width constraint. 确保您没有提供“固定”宽度约束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM