0

我正在继承 NSTextView 并覆盖 drawRect 方法,以便在 textview 周围绘制一个 NSBezierPathWithRoundedRect,但是 - 由于它具有圆形边缘,它们会干扰文本视图中的文本。

有什么方法可以在 NSTextView 的文本输入区域周围应用某种边距或填充,使其更加嵌入并远离圆形边缘?或者是将 NSTextView 放在 NSView 中并将圆形笔划应用于 NSView 的更好方法?

- (void)drawRect:(NSRect)dirtyRect {
// Drawing code here.
[super drawRect:dirtyRect];

NSRect rect = [self bounds];
NSRect newRect = NSMakeRect(rect.origin.x+2, rect.origin.y+2, rect.size.width-3, rect.size.height-3);

NSBezierPath *textViewSurround = [NSBezierPath bezierPathWithRoundedRect:newRect xRadius:10 yRadius:10];
[textViewSurround setLineWidth:2.0];
[[NSColor whiteColor] set];
[textViewSurround stroke];

}
4

2 回答 2

0

You could try setting margins on the paragraph style of the whole textView's string.

Or maybe put your textview inside a larger parent view with rounded corners and a border?

于 2015-01-15T09:28:13.277 回答
0

我认为 -setTextContainerInset: 可以满足您的需要。或者,您不应该在您的 -drawRect: 实现中调用 super 并自己绘制文本容器。

于 2010-02-16T12:08:00.933 回答