我有一个子类NSBox。在内部,我嵌入了一些NSTextfields,它们在角落处显示了一些奇怪的伪像(请参见image here)。这是我的NSBox子类代码:

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


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

最佳答案

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

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


}

10-07 23:05