Reputation: 827
How to create a uilabel
in swift with dynamic height so that line breaks automatically.
label = UILabel();
var str = " khduhfi8wde fwei9jfriuwqef iwfiuwqef iefiedf ejfiejfi9e eihjfiefi8e eifiejh";
label.frame = CGRectMake(50, 50, 100, 100);
label.text = str;
view.addSubview(label);
Upvotes: 1
Views: 965
Reputation: 22236
In Interface Builder, set a high priority to the width of the label, then set the hugging priority to high.
Also, do not forget to set numberOfLines to 0.
Text will then display with dynamic height.
Upvotes: 1