iphoneios7uinavigationcontrolleruibarbuttonitemios7.1

Custom button Image not visible on navigation bar iOS 7.1


I had added custom button on my navigation bar. here is the code now my problem is that in iOS7 I am able to see back Button image with text, while in iOS 7.1 the image is not displaying only text is displaying. This is iOS 7.1This is iOS 7

-(void)addBackButton{

    self.navigationItem.hidesBackButton = YES;

    [backButtonView removeFromSuperview];

   if (backButtonView) {
       [backButtonView release];
      backButtonView = nil;
   }

    backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0,6,70,30)];

    NSString *strText = @"Back";

     btnBack = [[UIButton alloc] initWithFrame:CGRectMake(2,0, 70, 31)];

     [btnBack setTitle:strText forState:UIControlStateNormal];
     btnBack.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:17];
     btnBack.titleLabel.textColor = IOS7ColorBtnBackText;
     [btnBack setImage:[UIImage imageNamed:@"Left_Arrow.png"] forState:UIControlStateNormal];

     [btnBack addTarget:self action:@selector(btnBack:) forControlEvents:UIControlEventTouchUpInside];

     [backButtonView addSubview:btnBack];
     [btnBack release];

      [self.navigationController.navigationBar addSubview:backButtonView];


}

Solution

  • Instead of adding it as subview in navigationView you can assign custom button to left or right button and this too works

      UIButton *backbtn=[[UIButton alloc]initWithFrame:CGRectMake(20,5,42, 42)];
      [backbtn setImage:[UIImage imageNamed:@"arrow.png"] forState:UIControlStateNormal];
      [backbtn setTitle:@"Login" forState:UIControlStateNormal];
      [backbtn addTarget:self action:@selector(didTapBackButton:) forControlEvents:UIControlEventTouchUpInside];
      UIBarButtonItem *barbtn=[[UIBarButtonItem alloc]initWithCustomView:backbtn];
      self.navigationItem.leftBarButtonItem=barbtn;