开发者

NSTextView and NSTextContainer size & clipping area

I found very interesting behavior of text container inside NSTextView. When i set size of container so it less than size of NSTextView frame and try draw any figures (like lines, rectangles) in NS开发者_JAVA技巧TextView drawRect: , all my figures clipped to size of text container.

So, frame size of NSTextView "allows" me to use it for drawing, but seems that is limited to container size.

If there are any possibility to draw inside text view but outside of text container ?

Code in Custom NSTextView - (void) drawRect:

[super drawRect:dirtyRect];

NSBezierPath* aPath = [NSBezierPath bezierPath];
[aPath moveToPoint:NSMakePoint(100, 100)];
[aPath lineToPoint:NSMakePoint(500, 100)];
[aPath stroke];

Custom textview resize policy set, so it resizes in all dimensions with container. This is code for custom NSTextView

- (void) setFrameSize:(NSSize)newSize {

    [super setFrameSize:newSize];

    NSTextContainer *container = [self textContainer];
    newSize.width -= 200;
    [container setContainerSize:newSize];
}


Thanks Ross Carter for advice:

Try wrapping the call to super like this:

[NSGraphicsContext saveGraphicsState];
[super drawRect:rect];
[NSGraphicsContext restoreGraphicsState];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜