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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With