Change Color of NSButton


/ Published in: Objective C
Save to your folder(s)

A Modular method to set new text with color of an NSButton. Thanks go to the owner of this code - RayNewbie - in the Apple discussion forum.


Copy this code and paste it in your HTML
  1. - (void)setButtonTitleFor:(NSButton*)button toString:(NSString*)title withColor:(NSColor*)color {
  2. [style setAlignment:NSCenterTextAlignment];
  3. NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
  4. color, NSForegroundColorAttributeName, style, NSParagraphStyleAttributeName, nil];
  5. NSAttributedString *attrString = [[NSAttributedString alloc]
  6. initWithString:title attributes:attrsDictionary];
  7. [button setAttributedTitle:attrString];
  8. [style release];
  9. [attrString release];
  10. }

URL: https://discussions.apple.com/message/9334854#9334854

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.