我想在表格视图的单个单元格中的文本项旁边显示一个图标。
我想要实现的一个例子是系统偏好设置中的应用程序列表 - >用户帐户 - >登录项目。
什么是好方法?
答案 0 :(得分:0)
这里有一个很好的例子: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