Search code examples
iosiphoneios7uinavigationitem

Custom leftBarButtonItem issue in ios 7


I have problem on custom left bar button item in ios 7 and above. Here i can move the button frame (x pos = -10). But could not change left bar button x pos.

Here my code:

BackButton *backButton = [[BackButton alloc] initWithFrame:CGRectMake(0, 0, 60, 44) viewFrom:self];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = customBarItem;

self.navigationItem.leftBarButtonItem.customView.backgroundColor = [UIColor yellowColor];

In iOS 7.1: enter image description here

In iOS 6.1 enter image description here

Kindly anyone help me to archive this. Thanks in Advance...


Solution

  • One Solution is make a UIButton and add to a navigationBar subViews. Example:

    UIButton *backButton = [UIButton alloc] initWithFrame:CGRectMake:(0,0,60,44)];
    backButton.backgroundColor = [UIColor yellowColor];
    [self.navigationController.navigationBar addSubview:backButton];
    

    Hope this helps!