I have two labels set completely programmatically. Label two should always be up against the right edge of label one (with a small space between them). Label one has its width set to be equal to its content size unless it hits a max width. Visually:
|Label one| |Label two|
I need the following constraints:
-
Label one should resize width wise unless it hits a max size.
-
Label two should always be up against the right edge of label one
How do I set these constraints programmatically?
2
Answers
lessThanOrEqualToConstant
for thewidthAnchor
should do the job.I agree with @Kevvv answer but you have to also assign trailing constraint of labelTwo to view’s trailing, because if labelTwo width will increase if content size is more.
just add one or more constraint