iOS后退按钮没有填充

时间:2015-09-09 14:56:16

标签: ios uinavigationcontroller

当我在导航堆栈上按下视图控制器时,后退按钮似乎是在屏幕的左侧。如何获得后退按钮的常规填充?

No padding

以下是我如何呈现视图控制器:

- (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];
}

这是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];

2 个答案:

答案 0 :(得分:4)

根据Apple文档,您无法在任何情况下编辑或修改后退按钮。只允许后退按钮操作hideself.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 。 因此,如果您想要使用后退按钮,您需要隐藏它并创建一个自定义左栏按钮项作为后退按钮。

subtract_value

答案 1 :(得分:1)

将此放入AppDelegate

[[UIBarButtonItem appearance] setBackButtonBackgroundVerticalPositionAdjustment:-3 forBarMetrics:UIBarMetricsDefault];