If I set textLayer.wrapped = YES, how do I resize textLayer to contain the wrapped text? I.e., how do I get the new height of the textLayer?
Basically, I want something like -[UILabel sizeToFit].
If I set textLayer.wrapped = YES, how do I resize textLayer to contain the wrapped text? I.e., how do I get the new height of the textLayer?
Basically, I want something like -[UILabel sizeToFit].
Copyright © 2021 Jogjafile Inc.
The first thing you need to do is get the size of the text.
Thankfully, the NSString UIKit Additions Reference offers a method to do exactly that:
That will give you a
CGSizethat you can then use to set the frame of yourUILabelor whatever subclass ofUIViewthat you're using.So, assuming
textLayeris aUILabel- rather than aCALayer- you'll end up with something like this: