Search code examples
iosnsstringnsattributedstringcontentsize

calculate the text that can be contained in a container with a particular size


I'm searching for a way to get the range of NSAttributedString that can be contained inside containers with a particular size.

Some more details :

The text is dynamic, i'm getting it with api calls. The layout is very similar to layouts used inside flipboard application : I have the dynamic number of pages, some of pages have an image on top with a dynamic height, the remaining space have to be filled with text


Solution

  • You can determine a bounds (size) of text using UIKit additions to NSString: https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/index.html

    So you can start with small amount of text and incrementally increase it until you reach required size.