NSCell Custom Highlight

前端 未结 1 955
借酒劲吻你
借酒劲吻你 2021-02-06 12:51

I\'m trying to subclass NSCell to draw a custom background highlight. The documentation seems to suggest that the overriding highlight:withFrame:inView:

相关标签:
1条回答
  • 2021-02-06 13:14

    Thanks to the help of @Bavarious I've managed to work it out. My extended NSTextFieldCell class implementation now contains:

    -(NSColor *)highlightColorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
        return nil;
    }
    
    - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
        if ([self isHighlighted]) {
            // Draw highlight background here
        }
    
        [super drawInteriorWithFrame:cellFrame inView:controlView];
    }
    

    The key is to make sure you return nil for highlightColorWithFrame:inView: to stop drawInteriorWithFrame:inView: drawing a background and yet still calling it to draw the main content (in this case text).

    0 讨论(0)
提交回复
热议问题