【发布时间】:2012-07-17 10:50:04
【问题描述】:
我想在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 内?
【问题讨论】:
标签: objective-c cocoa icons image-resizing nstabview