1
我想用一些文字将图标添加到NSTabViewItem
。cocoa:如何使用方法drawlabel:inRect in cocoa将图标添加到NSTabViewItem?
请帮我用drawLabel:inRect:
方法中的代码。
- (id)initWithCoder:(NSCoder *)decoder
{
[super initWithCoder:decoder];
tabCell = [[NSBrowserCell alloc] initImageCell:[NSImage
imageNamed:@"xyz"]];
[tabCell setLeaf:YES];
[tabCell setFont:[[self tabView] font]];
[tabCell setStringValue: [self label]];
return self;
}
- (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
{
{ // modify the rect a tad so the cell draws properly..
tabRect.origin.y += 2;
tabRect.size.width += 16;
}
[tabCell drawWithFrame:tabRect inView:[self tabView]];
}
- (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
{
NSSize superSize = [super sizeOfLabel:shouldTruncateLabel];
NSImage *icon = [tabCell image];
superSize.width += [icon size].width-4;
return superSize;
}
我可以一个图标添加到NSTabViewItem
但图标是走出来的标签,因为它的大尺寸。如何维持图标的大小以保持TabViewItem
?