Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the color of an NSButtonCell text label

How do I set the color of an NSButtonCell's label (title) text, that is the column cell for a table view? In my case, it is an checkbox button cell. (Is it possible using IB?)

like image 216
febeling Avatar asked Oct 14 '10 11:10

febeling


2 Answers

Try this one,, i think its perfect one.

NSColor *color = [NSColor redColor];
NSMutableAttributedString *colorTitle =
    [[NSMutableAttributedString alloc] initWithAttributedString:[button attributedTitle]];

NSRange titleRange = NSMakeRange(0, [colorTitle length]);

[colorTitle addAttribute:NSForegroundColorAttributeName
                   value:color
                   range:titleRange];

[button setAttributedTitle:colorTitle];
like image 128
Muhammad Rizwan Avatar answered Oct 20 '22 06:10

Muhammad Rizwan


You could try an attributed string value.

NSColor *txtColor = [NSColor redColor];
NSFont *txtFont = [NSFont boldSystemFontOfSize:14];
NSDictionary *txtDict = [NSDictionary dictionaryWithObjectsAndKeys:
        txtFont, NSFontAttributeName, txtColor, NSForegroundColorAttributeName, nil];
NSAttributedString *attrStr = [[[NSAttributedString alloc]
        initWithString:@"Hello!" attributes:txtDict] autorelease];
[[attrStrTextField cell] setAttributedStringValue:attrStr];
[attrStrTextField updateCell:[attrStrTextField cell]];
like image 31
Pierre Bernard Avatar answered Oct 20 '22 05:10

Pierre Bernard