Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios7 navigation bar : 3 strange dots appearing when back animation with custom button

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 ?

like image 959
user3820585 Avatar asked Oct 10 '14 09:10

user3820585


3 Answers

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];
like image 103
Adinp Avatar answered Nov 10 '22 21:11

Adinp


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];
}
like image 2
Suhail kalathil Avatar answered Nov 10 '22 20:11

Suhail kalathil


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

like image 2
Rendel Avatar answered Nov 10 '22 20:11

Rendel