Chetan Purohit Chetan Purohit - 1 year ago 109
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