我正在继承 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];
}