Hi,
CellAttributes are used by button and button cell for displaying
image and text accordingly, but tableHeaderCell doesn't uses these
attributes for displaying image and text.. Customize the
NSTableHeaderCell and draw the image and text in drawWithFrame method.
Thanks
SKiranKumar
On 16-Nov-09, at 4:12 PM, Symadept wrote:
Hi,
I am trying to display custom image and the attributed text into the
TableHeaderview. For this I am retrieving the HeaderCell of each
TableColumn
and setting its image and attributed text. Then I found out If I set
image
first and then text next, only attributed text shown with the default
headerview background. If the Image is set after Text then
Background image
overlaps the text.
I am overriding NSTableView and doing two things.
1. setDrawsBackground:NO
2. Invoking empty drawBackgroundInClipRect:clipRect.
Here is my code.
- (void)setColumnHeaderOf:(id)identifier image:(NSImage*)image title:(
NSString*)title
{
NSTableColumn *column=[self tableColumnWithIdentifier:identifier];
[[column headerCell] setCellAttribute:NSCellHasImageOnLeftOrBottom to:
NSImageBelow];
[[column headerCell] setImage:image];
NSMutableAttributedString *attributedString =
[[NSMutableAttributedString
alloc] initWithString:title];
NSMutableParagraphStyle * aParagraphStyle = [[[NSMutableParagraphStyle
alloc] init] autorelease];
[aParagraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[aParagraphStyle setAlignment:NSCenterTextAlignment];
CGFloat dividingFactor = 255.0f;
NSMutableDictionary * aTitleAttributes = [[[NSMutableDictionary alloc]
initWithObjectsAndKeys:
[NSFont fontWithName:CP_FONT_NAME size:[NSFont systemFontSize]],
NSFontAttributeName,
aParagraphStyle, NSParagraphStyleAttributeName,
nil] autorelease];
[aTitleAttributes setValue:[NSColor colorWithDeviceRed:(246/
dividingFactor)
green:(204/dividingFactor) blue:(37/dividingFactor) alpha:1.0f]
forKey:
NSForegroundColorAttributeName];
[attributedString addAttributes:aTitleAttributes range:NSMakeRange(0,
[attributedString length])];
[[column headerCell] setAttributedStringValue:attributedString];
[attributedString release];
}
- (void)awakeFromNib
{
NSLog(@"KBCustomTableView awakeFromNib");
[[self enclosingScrollView] setDrawsBackground:NO];
NSRect frameRect = [[self headerView] frame];
[[self headerView] setFrameSize:NSMakeSize(frameRect.size.width, 30)];
[self setColumnHeaderOf:@"Column1" image:[NSImage
imageNamed:@"ColHdr1"]
title:@"Column1"];
[self setColumnHeaderOf:@"Column2" image:[NSImage
imageNamed:@"ColHdr2"]
title:@"Column2"];
[self setColumnHeaderOf:@"Column3" image:[NSImage
imageNamed:@"ColHdr3"]
title:@"Column3"];
}
- (void)drawBackgroundInClipRect:(NSRect)clipRect
{
NSLog(@"KBCustomTableView drawBackgroundInClipRect");
//[super drawBackgroundInClipRect:clipRect];
}
Thanks in advance.
Regards
symadept
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/kirankumar.s%40prithvisolutions.com
This email sent to kirankuma...@prithvisolutions.com
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com