简体   繁体   中英

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 NSTextView 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM