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-
Now it is appearing like this-
As shown in above screen-shot, when I used this code I faced few problems:
- Column header titles are not getting displayed.
- Header column separators are not appearing.
Can anyone suggest me how to resolve these problems or some better way to implement it?
You have to customize the
NSTableHeaderCell
and fill the gradient inNSCell'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;