Reputation: 8695
How do I make an NSLayoutManager that assigns each paragraph in its text to a different NSTextContainer?
This would be similar to the multiple page/column usage that is common in TextKit, but each page corresponds to a different paragraph of variable length.
Upvotes: 3
Views: 913
Reputation: 1998
Another way is inserting page break control character (ASCII code: 12) at the end of each paragraph.
Upvotes: 0
Reputation: 3100
I think the easiest way to do this is to subclass NSTextContainer and override
- (CGRect)lineFragmentRectForProposedRect:(CGRect)proposedRect atIndex:(NSUInteger)characterIndex writingDirection:(NSWritingDirection)baseWritingDirection remainingRect:(CGRect *)remainingRect
In your custom method, you'd inspect the attributes at characterIndex
and see if they matched the paragraph that text container is assigned to. If they are, just return super
's implementation of the method, otherwise return CGRectZero
to signify that the proposed rect is invalid for this text container. This does mean you'll have to track paragraph attributes and the text containers they correlate to (and vice versa).
Upvotes: 5