2010-10-14 14 views

risposta

9

È possibile provare un valore di stringa attribuito.

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

È possibile passare '0.0' per la dimensione per ottenere la dimensione normale predefinita. Puoi anche chiedere a NSFont qualcuna delle altre dimensioni (ad esempio, la dimensione per i controlli e le celle di piccole dimensioni). In genere non si dovrebbe passare una dimensione esplicita. –

12

Prova questo, penso che sia perfetto.

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]; 
Problemi correlati