Line number control skills of uilabel

Time:2022-1-2

The number of rows of uilabel is controlled, for example, 2 rows are displayed

First, everyone will:

label.numberOfLines = 2

The second type can be controlled by font size and label size

label.font = UIFont.semibold(ofSize: 16)
label.frame.size = // ...

coordination

label.numberOfLines = 0



Line number control skills of uilabel
After designing according to the second method,

The first two effects are very natural,

Why is the effect of the third label vertically centered?

Not up a little.

Set as follows:

Center constraint of label = top of view + constant

(about offset of 30)

Then you can,

Center one line

Two line presentation

If there are more than two lines, an ellipsis will appear

github repo