Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 14th, 2012  |  syntax: None  |  size: 1.33 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Navigation Controller not working properly
  2. if([[UINavigationBar class] respondsToSelector:@selector(appearance)]) //iOS >=5.0
  3. {
  4.     [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
  5. }
  6. else
  7. {
  8.     self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"header.png"].CGImage;
  9. }
  10.        
  11. UINavigationController *navControl;
  12.        
  13. UINavigationBar *navBar = self.navControl.navigationBar;
  14.    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
  15.             imgView.image = [UIImage imageNamed:@"header.png"];
  16.             [navBar addSubview:imgView];
  17.             [imgView release];
  18.        
  19. @implementation UINavigationBar (CustomImage)
  20.  
  21. - (void)drawRect:(CGRect)rect {
  22.     UIImage *image = [UIImage imageNamed:@"background.png"];
  23.     [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  24. }
  25.  
  26. @end
  27. implement this code in your .m file
  28.  
  29.  
  30. @implementation ImageViewController
  31.  
  32. - (void)viewDidLoad {
  33.     [super viewDidLoad];
  34.     self.navigationController.navigationBar.tintColor = [UIColor blackColor];
  35.     UIImageView *backGroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
  36.     [self.navigationController.navigationBar insertSubview:backGroundView atIndex:0];
  37.     [backGroundView release];
  38. }
  39.  
  40. @end