1

我有一个子类 NSBox。在里面我嵌入了一些 NSTextfields,它们在它们的角落显示了一些奇怪的伪影(见这里的图片)。这是我的 NSBox 子类代码:

    - (void)drawRect:(NSRect)rect {
    NSBezierPath* rectanglePath = [NSBezierPath bezierPathWithRoundedRect:rect
                                                                  xRadius: 4
                                                                  yRadius: 4];
    [NSColor whiteColor];
    [rectanglePath fill];
}

有任何想法吗?谢谢,托马斯

4

1 回答 1

2

解决问题的方法是使用 [self bounds] 而不是 rect 参数。

- (void)drawRect:(NSRect)rect {
NSBezierPath* rectanglePath = [NSBezierPath bezierPathWithRoundedRect:[self bounds]
                                                              xRadius: 4
                                                              yRadius: 4];
[NSColor whiteColor];
[rectanglePath fill];

}

于 2015-03-06T14:31:56.260 回答