I have a multi-line UILabel ( numberOfLines = 0). Its width may change at runtime, and sometimes this leads to truncation and / or repacking. Some examples illustrate this best:
Example 1: reducing the width leads to a different point of line break


Example 2: reducing the width leads to truncation


Example 3: decreasing the width results in both truncation and a different line break position


Example 4: decreasing width does not affect truncation or line break position


Since this change in formatting can be quite dramatic, I intend to mask it behind some animation (it may fade in / out). However, the first hurdle is determining when I need to do this. I donβt want to apply animation whenever the label size changes - only when it leads to a change in either truncation or line break position.
How can I check this? The test should return YES, for example, 1, 2, and 3, but NO, for example, 4.
Note. Resizing will never change the number of rows in my example.
Note 2: if someone has the best tags related to text formatting, I would like to know them - feel free to edit.
Note 3: if you are interested in having this behavior, try Apple mail.app on iPhone. While browsing your Inbox, swipe through the email and look at the final fade-in / out line as it wraps and / or truncates again (but not when it's not needed).
ios objective-c cocoa-touch uilabel uiview
Ben Packard Oct 18 2018-12-12T00: 00Z
source share