我想在表视图的单个单元格中的文本项旁边显示一个图标。
我想要实现的一个示例是“系统偏好设置”->“用户帐户”->“登录项”中的应用程序列表。
有什么好办法呢?
这里有一个很好的例子如何做到这一点:http://www.cocoadev.com/index.pl?IconAndTextInTableCell http://www.cocoadev.com/index.pl?IconAndTextInTableCell您可以制作自己的自定义 NSCell,它可以绘制图像和文本
@interface IconCell : NSCell
{
NSArray * cellValue;
}
- (void)setObjectValue:(id <NSCopying>)object;
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
@implementation IconCell
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSDictionary * textAttributes =
[NSDictionary dictionaryWithObjectsAndKeys:[NSFont
userFontOfSize:10.0],NSFontAttributeName, nil];
NSPoint cellPoint = cellFrame.origin;
[controlView lockFocus];
[[cellValue objectAtIndex:1] compositeToPoint:NSMakePoint(cellPoint.x+2,
cellPoint.y+14) operation:NSCompositeSourceOver];
[[cellValue objectAtIndex:0] drawAtPoint:NSMakePoint(cellPoint.x+18,
cellPoint.y) withAttributes:textAttributes];
[controlView unlockFocus];
}
- (void)setObjectValue:(id <NSCopying>)object
{
cellValue = (NSArray *)object;
}
@end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)