Reputation: 3134
When I push a viewcontroller on my navigation stack, the back button appears to be against the left side of the screen. How can I get the regular padding of the back button?
Here is how I present the view controller:
- (void)goToCollection:(UIButton *)btn {
Card *colCard = (Card *)btn.userData;
WViewController *vc = [WViewController new];
NSString *colID = [[colCard.href componentsSeparatedByString:@"/"] lastObject];
vc.collectionID = colID;
[self.navigationController pushViewController:vc animated:YES];
}
Here's my view setup in didFinishLaunchingWithOptions
:
//Profile View
ProfileViewController *pv = [ProfileViewController new];
UINavigationController *profNav = [[UINavigationController alloc] initWithRootViewController:pv];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:profNav];
[self.window setTintColor:[UIColor Primary]];
[self.window makeKeyAndVisible];
Upvotes: 2
Views: 4947
Reputation: 244
As per apple documentation, you can not edit or modify back button in any case. Only allowed operation for back button is show
and hide
.
So if you want something to do with back button, you need to hide it and create a customise left bar button item as back button.
self.navigationItem.hidesBackButton = YES; //hides back button
UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)]; // creates a new button
[myButton setImage:[UIImage backButtonImage]; // sets image for new button
[myButton setContentEdgeInsets:UIEdgeInsetsMake(0, -15, 0, 0)];//content edgeInset to provide required padding
[myButton addTarget:self action:@selector(backToHOmePage) forControlEvents:UIControlEventTouchUpInside];//adding target for new button
UIBarButtonItem *customBackBtn = [[UIBarButtonItem alloc] initWithCustomView:myButton]; //custom bar button item
self.navigationItem.leftBarButtonItem = customBackBtn; //assigning to left bar button item
-(void)backToHOmePage
{
[self.navigationController popViewControllerAnimated:YES];
} // method to be triggered on tapping above button
Upvotes: 4
Reputation: 3631
Put this in your AppDelegate
[[UIBarButtonItem appearance] setBackButtonBackgroundVerticalPositionAdjustment:-3 forBarMetrics:UIBarMetricsDefault];
Upvotes: 1