2010-10-14 8 views

Répondre

9

Vous pouvez essayer une valeur de chaîne attribuée.

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]]; 
+2

Vous pouvez passer '0,0' pour la taille afin d'obtenir la taille normale par défaut. Vous pouvez également demander NSFont pour l'une des autres tailles (par exemple, la taille pour les petits contrôles et les cellules). Vous ne devriez généralement pas passer une taille explicite. –

12

Essayez celui-ci, je pense que c'est parfait.

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]; 
Questions connexes