Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Monaj

macrumors regular
Original poster
May 24, 2009
193
0
Hi all,

I am displaying buttons in NSMatrix.

My requirement is:

Code:
to change color of button title and place an image at beginning of title, when certain condition is satisfied.

To do so, I used following code:

// setting attributed text

Code:
NSAttributedString *selectedCellAttribute;
 
 
NSFont *selectedCellFont = [NSFont fontWithName:@"Lucida Grande" size:11];
 
NSColor *selectedCellColor = [NSColor redColor];
 
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
 
[style setAlignment:NSCenterTextAlignment];
 
 
 // setting image
 
NSTextAttachment *imageAttachment = [[NSTextAttachment alloc] init];
 
NSCell *cell = [imageAttachment attachmentCell];
 
[cell setImage:[NSImage imageNamed:@"caution_small.png"]];
 
 
NSDictionary *selectedCellDictionary = [NSDictionary dictionaryWithObjectsAndKeys:imageAttachment,NSAttachmentAttributeName,selectedCellFont,NSFontAttributeName,selectedCellColor,NSForegroundColorAttributeName,style,NSParagraphStyleAttributeName,nil];
 
 
// recognizing cell
 
 
NSButtonCell *associatedCell = [associatesMatrix cellAtRow:0 column:2];
 
selectedCellAttribute = [[NSAttributedString alloc] initWithString:[associatedCell title] attributes:selectedCellDictionary];
 
[associatedCell setAttributedTitle:selectedCellAttribute];

Although above code is showing change in color of title, it is showing no image placed in beginning of title :(

Can anyone suggest me where I may be wrong or some other method to implement my requirements?

Edit:

At line: NSCell *cell = [imageAttachment attachmentCell];

it is giving this warning when compiled:
type 'id <NSTextAttachmentCell>' does not conform to 'NSCopying" protocol.


Thanks,

Monaj
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.