Search code examples
objective-ccocoauser-interfacenstextfieldnsbox

UI issues with custom NSBox


I have a subclassed NSBox. Inside I have some NSTextfields embedded, which show some strange artifacts in their corners (see image here). This is my subclass code for the NSBox:

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

Any ideas? Thanks, Thomas


Solution

  • What solved the problem was using [self bounds] instead of the rect argument.

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

    }