2012-09-20 15 views
5

Duplicar posible:
Setting UILabel - Font through code - generates error - iPhone¿Cómo puedo cambiar la fuente de una etiqueta mediante programación?

Quiero saber ¿hay alguna manera de establecer la fuente de una etiqueta mediante programación, ya que necesito para cambiar el tipo de letra en mi aplicación cuando una condición es establecido verdadero. ¿Cómo puedo hacerlo usando la variedad de fuentes de Apple?

+0

Ver [esto] (http://stackoverflow.com/q/1380490/730701) y [este] (http://stackoverflow.com/q/1302833/730701). – Adam

+0

eche un vistazo rápido a ** [Referencia de la clase UILabel] (http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UILabel_Class/Reference/UILabel.html) **, espero que lo haya hecho No digo nada nuevo con eso ... – holex

Respuesta

12

Hágase una lista de fuentes disponibles:

for(NSString *strFamilyName in [UIFont familyNames]) { 
    for(NSString *strFontName in [UIFont fontNamesForFamilyName:strFamilyName]) { 
    NSLog(@"%@", strFontName); 
    } 
} 

Ahora set Fontlike esto:

[yourLabel setFont:[UIFont fontWithName:@"your font name here" size:fontsizehere]]; 

EDITAR:

Por ejemplo así:

[yourLabel setFont:[UIFont fontWithName:@"Arial" size:15]]; 
+4

[Deja vu] (http://stackoverflow.com/a/1380548/730701)? – Adam

+0

Muchas gracias por su ayuda @Príncipe – iHackerMe

1

Aquí utiliza este código.

[labelname setFont:[UIFont fontWithName:@"American Typewriter" size:18]]; 
1

Set como esta etiqueta // establecer

UIFont *font = [UIFont fontWithName:@"MyFont" size:20]; 
    [label setFont:font]; 
1

label.font = [UIFont fontWithName:@"Calibri" size:15]; 

// establecer etiqueta de color

label.textColor = [UIColor redColor]; 

// establecer RILC etiqueta si tiene valor RGB

label.textColor = [UIColor colorWithRed:180.0/255.0 green:6.0/255.0 blue:47.0/255.0 alpha:1.0]; 
Cuestiones relacionadas