I would like to use the back navigation animation using
[self.navigationController popViewControllerAnimated:YES]
with a custom button added to the navigation bar.
As I don't want the back button to be seen, i've hidden it with self.navigationItem.hidesBackButton = YES;
But during the back animation, on ios7 (not ios6) 3 dots can be seen sliding in the navigation bar.
They are not appearing with self.navigationItem.hidesBackButton = NO;
but of course the button can be seen.
Does anyone has any idea to make them not appearing ?
If you set
self.navigationItem.hidesBackButton = YES
iOS will sometimes generate three dots inside its generic back button. I solved the problem by setting the text on the generic back button to be empty and then I created my custom button. This is how I set the empty text:
UIBarButtonItem *backButton2 = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton2;
And then I created my custom UIButton and placed it where I wanted it like this:
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 70/2-22, 44, 44)];
[backButton setImage:[[UIImage imageNamed:@"back_button.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
backButton.tintColor = tintColor;
backButton.imageEdgeInsets = UIEdgeInsetsMake(-2, -15, 0, 0);
[backButton addTarget:self action:@selector(popCurrentViewController) forControlEvents:UIControlEventTouchUpInside];
No need to hide the backButton
, you can just add custom back button, it will hide the default button.
- (void) viewDidLoad
{
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(handleBack:)];
self.navigationItem.leftBarButtonItem = backButton;
}
- (void) handleBack:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
Just add these following lines in viewWillAppear method:
Swift:
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
Objective C:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
That's all
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