Given is a (html) String with x-number of characters. The String will get formatted into an attributed String. Then displayed in a UILabel
.
The UILabel
has a height of >= 25
and <= 50
to limit the number of lines to 2.
Since the String has characters not visible in the formatted attributed String, like <b> / <i>
, the best approach would be to limit the character count of the attributed String.
UILabel
property .lineBreakMode = .byTruncatingTail
causes words to get cut.
The goal, in case the character count would exceed the limit of space in the UILabel
, is to cut between words. Desired maxCharacterCount = 50
. Determine the last space
before maxCharacterCount
. Cut the String and append ...
as last characters of the UILabel
.
What's the best approach to limit the characters? Help is very appreciate.