Reputation: 643
I need place some UIView right after text ends with some conditions:
If there are enough space from text end to the right edge of container, place view right after. If there are no room - place view above. The problem is - it should work for second line as well.
I know there are API to get frame of formatted text in UILabel, which kind of work for single line. I also know about exclusion path, but it will work only if attached view will be aligned right, but i need it to be placed right after text ends.
Do you know API of TextKit or some trick to achieve this goal?
Possible way to solve this i though is to get the text range from second line and then calculate frame of UILabel for that single line, but i can not find is there are interface to do that.
The whole question is: How to get width (frame) of the text on the second line of UILabel/UITextView?
Upvotes: 0
Views: 797
Reputation: 535
I have found something for you. please refer this answer. it may help you.
this answer has an algorithm that returns the length of NSString
that can fit into the UILabel
. and using that you can find the text of the first line.
After that, you can easily find the actual size of the second line based on the remaining text.
Upvotes: 1