문제

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.

도움이 되었습니까?

해결책

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).

다른 팁

Another way is inserting page break control character (ASCII code: 12) at the end of each paragraph.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top