2010-10-14 19 views

Respuesta

9

Puede intentar con un valor de cadena atribuido.

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

Puede pasar '0.0' para que el tamaño obtenga el tamaño normal predeterminado. También puede solicitar NSFont para cualquiera de los otros tamaños (por ejemplo, el tamaño para controles y celdas pequeños). Por lo general, no debes aprobar un tamaño explícito. –

12

Prueba este, creo que es el perfecto.

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]; 
Cuestiones relacionadas