2011-10-28 24 views

Respuesta

63

Ajuste el backBarButtonItem 's tintColor:

self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor]; 

TIP: Si desea que esto sea se aplica a todos los UIBarButtonItem casos en los que su aplicación de forma predeterminada, a continuación, puede utilizar la nueva API UIAppearance de hacer precisamente eso:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]]; 
+0

He intentado esto: (void) {viewDidLoad [ super viewDidLoad]; UIImageView * image = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "logobar.png"]]; NSLog (@ "Frame ==% f", image.frame.size.width); self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor]; self.navigationItem.titleView = image; NSLog (@ "% f", self.navigationItem.titleView.frame.size.width); } pero no está funcionando –

+0

El segundo método funcionó Gracias –

+0

[[UIBarButtonItem apariencia] setTintColor: [UIColor redcolor]]; Este método está presente para iOS 5.0 o superior cómo hacer que funcione para versiones más bajas? –

8

La primera línea de la respuesta de jacob no funcionó porque el backBarButtonItem era NULL. Es NULL porque se creó más tarde automáticamente al cambiar a otro ViewController. En ese momento se puede establecer el título del botón con

self.title = @"nice title"; // self is here the view(controller) within the popoverController 

pero no se puede establecer el tintColor.

Lo que funcionó para mí fue crear un nuevo UIBarButtonItem sin ningún estilo. A continuación, establezca las propiedades de título y color y configúrelo como backBarButtonItem.

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init]; 
backButton.title = @"go back - now!"; 
backButton.tintColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.7 alpha:1.0]; 
self.navigationItem.backBarButtonItem = backButton; 
[okButton release]; 
+0

Gracias. Funciona perfecto. – Philip007

3

Si desea que el botón se ve exactamente igual que en la imagen, se puede utilizar una imagen, también:

imagen
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"back_button_bg"] 
             forState:UIControlStateNormal 
             barMetrics:UIBarMetricsDefault]; 

El fondo debe ser una imagen de tamaño variable para obtener buenos resultados.

0

mejor manera que he encontrado para configurarlo de forma global o localmente es

[[UIBarItem appearance] setTitleTextAttributes: 
     [NSDictionary dictionaryWithObjectsAndKeys: 
     [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], UITextAttributeTextColor, 
     [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor, 
     [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, 
     [UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont, 
     nil] 
     forState:UIControlStateNormal]; 
-1
[[UINavigationBar appearance]setTintColor:[UIColor whiteColor]]; 

probar este Se está trabajando para mí ...

Cuestiones relacionadas