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.
-(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];
}
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;
[self.navigationItem setHidesBackButton:YES];
This do work, but you made mistake here
[self.navigationController.navigationBar addSubview:backButtonView];
///// Your code to create custom button goes here
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:BackButton];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With