Chetan Purohit Chetan Purohit - 2 years ago 149
iOS Question

How to apply limit of 2 lines for UILabel ,ios

I am creating an app in Swift. I am having an UILabel with dynamic data. I want to apply restriction of two lines to that UILabel i.e. it should do word wrapping and show text in just 2 lines only. Any solution will be appreciated. Thank you in advance.

Answer Source




titleLabel.numberOfLines = 0;
[titleLabel setLineBreakMode:NSLineBreakByWordWrapping]; 


titleLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping

titleLabel.numberOfLines = 2

// titleLabel.numberOfLines = 0                      //'0' means infinite number of lines

Inspector attribute

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download