user5772785
user5772785

Reputation:

OSX - how to change NSButton title color

My project have button as well as check box with default title color black i want to change color of title to red

Upvotes: 2

Views: 2474

Answers (1)

Ronak Chaniyara
Ronak Chaniyara

Reputation: 5435

Here's the code to set the button title color in a controller:

 NSColor *color = [NSColor greenColor];
 NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
 [style setAlignment:NSCenterTextAlignment];
 NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
 color, NSForegroundColorAttributeName, style, NSParagraphStyleAttributeName, nil];
 NSAttributedString *attrString = [[NSAttributedString alloc]
 initWithString:@"Title" attributes:attrsDictionary];
 [self.button setAttributedTitle:attrString];

may be this is all you want.

Upvotes: 1

Related Questions