我创建了一个自定义 NSTextFieldCell 并- (void)drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
在这里重写了我自己的绘图。但是,我在绘制背景时遇到了麻烦。如果不调用super
背景,则不会清除背景,随后的绘图会产生类似涂抹效果的东西。设置 drawsBackground 时不会发生这种情况,因为在这种情况下,我可以用背景颜色填充 cellFrame。
- (void)drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView {
if (self.drawsBackground) {
[self.backgroundColor set];
} else {
[NSColor.clearColor set];
}
NSRectFill(cellFrame);
[self.attributedStringValue drawInRect: cellFrame];
}
但是如果背景绘图被禁用,我该怎么做才能清除背景?我当然想让文本视图下的其他内容发光(所以,只是用超级视图的背景颜色擦除是没有解决方案的)。