Cell-based table view approach
With a cell-based table view you can't do this because the standard cell NSImageCell and NSTextCell can only display an image or text. You could make your down subclass of NSCell to make a cell that accepts both a image and text, for example, Display icon and text in same cell of NSTableView. To display different fonts and colors you will need to use a NSAttributedString
for example, (no checked this code Xcode so there could be a few bugs, but it gives you an idea),
NSString *redWord = @"Hello";
NSString *greenWord = @"World";
NSString *message = [NSString stringWithFormat:@"%@ %@", redWord, greenWord];
NSMutableAttributedString *text =
[[NSMutableAttributedString alloc]
initWithAttributedString:message];
[text addAttribute:NSForegroundColorAttributeName
value:[NSColor redColor]
range:NSMakeRange(0, [redWord length])];
[text addAttribute:NSFontAttributeName
value:[NSFont fontWithName:@"Arial Italic" size:12];
range:NSMakeRange(0, [redWord length])];
[text addAttribute:NSForegroundColorAttributeName
value:[NSColor greenColor]
range:NSMakeRange([redWord length] + 1, [greenWord length])];
[text addAttribute:NSFontAttributeName
value:[NSFont fontWithName:@"Times Bold" size:12];
range:NSMakeRange([redWord length] + 1, [greenWord length])];
View-based table view approach
View-based table view display NSTableCellView views in their the table cells. The standard NSTableCellView has a imageView
and textField
property so for your purpose this would seem like an ideal fit. Simply set the table view cell's image view to display your image, tableCellView.imageView.image = myImageset
then set the text you want to display in the text field, tableCellView.textField.attributeStringValue = myAttributedString
. Note you will have to use an attributed string to get the different colours and fonts (see above).