He estado tratando de cambiar la imagen de fondo de la UINavigationBar de mi solicitud. Lo intenté de varias maneras. Primero agregué a mi clase AppDelegate el siguiente código:Cambiar la imagen de fondo UINavigationBar
@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"navigationbar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end
Pero no funcionaba. Mi siguiente intento fue escribir una clase CustomizedNavigationBar que está anulando el método drawRect. Parecía que:
CustomizedNavigationBar.h
#import <UIKit/UIKit.h>
@interface CustomizedNavigationBar : UINavigationBar
@end
CustomizedNavigationBar.m
#import "CustomizedNavigationBar.h"
@implementation CustomizedNavigationBar
- (void) drawRect:(CGRect)rect {
UIImage *image = [UIImage imageNamed: @"navigationbar.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
NSLog(@"I got called!!!!!");
}
@end
En mi archivo .xib donde el navigationbar se define he cambiado la clase a la nueva CustomizedNavigationBar. Pero todavía no está funcionando ..
Como otra prueba de que he descargado un proyecto de ejemplo en el que la imagen de fondo debe ser cambiado. Pero incluso con ese código de muestra, no funcionaba.
¿Qué estoy haciendo mal? Estoy usando IOS 5. ¿Alguna sugerencia u otras formas en que podría definir una imagen de fondo?
Gracias por sus respuestas!
fin tengo una solución de trabajo
[http://stackoverflow.com/questions/9304817/uinavigationbar-setting-background-image][1] [1]: http: // stackoverflow.com/questions/9304817/uinavigationbar-setting-background-image –
Duplicado obsoleto de https://stackoverflow.com/questions/43602848/ –