Filling gradient in NSTableHeaderView not working properly

636 Views Asked by At

I am trying to fill gradient in header of tableview. So far I am able to achieve it by subclassing NSTableHeaderView and using this code in it-

- (void)drawRect:(NSRect)dirtyRect {
    // Drawing code here.

    NSGradient *gradientToFill = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedRed:0.8828125 green:0.8984375 blue:0.91015625 alpha:1.0]
                                                               endingColor:[NSColor colorWithCalibratedRed:0.5546875 green:0.59765625 blue:0.66015625 alpha:1.0] ];
    [gradientToFill drawInRect:dirtyRect angle:90];
}

So earlier it was appearing like this-

enter image description here

Now it is appearing like this-

enter image description here

As shown in above screen-shot, when I used this code I faced few problems:

  1. Column header titles are not getting displayed.
  2. Header column separators are not appearing.

Can anyone suggest me how to resolve these problems or some better way to implement it?

1

There are 1 best solutions below

0
On

You have to customize the NSTableHeaderCelland fill the gradient in NSCell's draw methods.You need to implement the following methods.

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

-(void)highlight:(BOOL)isHighlighted withFrame:(NSRect)cellFrame inView:(NSView *)view

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;