我对NSTextView进行了子类化,并重写了drawRect方法,以便在文本视图周围绘制一个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];
}
发布于 2010-02-16 12:08:01
我认为-setTextContainerInset:做了你需要的事情。或者,您不应该在-drawRect:的实现中调用super,而是自己绘制文本容器。
发布于 2015-01-15 09:28:13
您可以尝试在整个textView字符串的段落样式上设置边距。
或者把你的文本视图放在一个更大的带有圆角和边框的父视图中?
https://stackoverflow.com/questions/2272641
复制