I subclassed NSTabView and added 5 TabViewItem, now i wanted to add an Icon along with the title in the NSTabViewItem, Can anyone suggest me how to start, i am not getting any documentation except,
- (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect开发者_StackOverflow社区)tabRect
Does that mean, if i override this method, i need to draw Icon and string my own,
For setting up the title , i am using following method,
[pTabViewItem setLabel:pLabelTitle];
Kind Regards
RohanNever Mind, Following Code works for me,
- (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect{
// do we have an image to draw
NSImage *pImage = [pDelegate imageForCell];
[[NSGraphicsContext currentContext] saveGraphicsState];
NSAffineTransform* xform = [NSAffineTransform transform];
[xform translateXBy:0.0 yBy: tabRect.size.height];
[xform scaleXBy:1.0 yBy:-1.0];
[xform concat];
CGFloat x_Offset =0;
if(pImage){
[pImage drawInRect:NSMakeRect(tabRect.origin.x-8,-6,16, 16)fromRect:NSZeroRect
operation:NSCompositeSourceOver
fraction:1.0];
x_Offset = 16;
}
[[NSGraphicsContext currentContext] restoreGraphicsState];
[super drawLabel:shouldTruncateLabel inRect:tabRect];
}
Why transformation:
Image was showing inverted, so i need to transform,
Why offset: Even after transformation, i need to adjust, the position so that it looks just before the title,
and guys, i while setting the title,
append a Space, so title will not overlap the image, i know this is ugly approach, but couldn’t get any other quick way to do it, if i draw the text myself then i need to take care of truncating also,
Thanks to those who looked at questions and answer
Kind Regards
Rohan
精彩评论