首页 文章

NSTextView在Cocoa中舍入边框/笔划

提问于
浏览
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];

}

2 回答

  • 0

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

  • 0

    您可以尝试在整个textView的字符串的段落样式上设置边距 .

    或者可能将您的textview放在一个带圆角和边框的较大父视图中?

相关问题