create custom label with two lines and truncating tail in swift

To create a custom label with two lines and truncating the tail in Swift, you can use the UILabel class and set the numberOfLines property to 2. For truncation, you can use the lineBreakMode property to set the mode to .byTruncatingTail. Here is an example code snippet:

main.swift
let myLabel = UILabel()
myLabel.numberOfLines = 2
myLabel.lineBreakMode = .byTruncatingTail
myLabel.text = "This is a long text that will be truncated at the end of the second line"
182 chars
5 lines

This will create a UILabel with two lines and truncate the text at the end of the second line with an ellipsis.

gistlibby LogSnag