Chetan Purohit Chetan Purohit - 6 months ago 36
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

set

Programmatically

Objective-C

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

Swift

titleLabel.lineBreakMode = NSLineBreakMode.ByWordWrapping

titleLabel.numberOfLines = 2

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

Inspector attribute

enter image description here

Comments