Remove back arrow in iOS7

2019-01-22 19:39发布

enter image description here

I want to incorporate a custom back button - I'm able to get the above result using

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back-btn"] style:UIBarButtonItemStylePlain target:nil action:nil];

but how do you remove the native blue button?

8条回答
ゆ 、 Hurt°
2楼-- · 2019-01-22 20:23

Thanks to all the answerers - found a simpler way of doing it...

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back-btn"] style:UIBarButtonItemStylePlain target:self action:@selector(backButtonAction:)];
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];

[self.navigationItem setHidesBackButton:YES animated:NO];
[self.navigationItem setBackBarButtonItem:nil];

-(void) backButtonAction:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
查看更多
甜甜的少女心
3楼-- · 2019-01-22 20:24

Swift 4 (if you just want to hide it)

let mask = UIImage()
navigationController?.navigationBar.backIndicatorImage = mask
navigationController?.navigationBar.backIndicatorTransitionMaskImage = mask
查看更多
\"骚年 ilove
4楼-- · 2019-01-22 20:32

Check this one:

    UIImage *faceImage = [UIImage imageNamed:@"back_arrow.png"];
    UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];
    face.bounds = CGRectMake( 10, 0, faceImage.size.width, faceImage.size.height );
    [face addTarget:self action:@selector(handleBack:) forControlEvents:UIControlEventTouchUpInside];
    [face setImage:faceImage forState:UIControlStateNormal];
    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:face];
    self.navigationItem.leftBarButtonItem = backButton;
    [self.navigationItem setHidesBackButton:YES animated:YES];
    [self.navigationItem setBackBarButtonItem:nil];


  -(IBAction)handleBack:(id)sender
  {
     //    [self dismissViewControllerAnimated:YES completion:nil];
     [self.navigationController popViewControllerAnimated:YES];
  }
查看更多
女痞
5楼-- · 2019-01-22 20:33

Use the below code to hide the back arrow:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back-btn"]
                                                                         style:UIBarButtonItemStylePlain
                                                                        target:nil
                                                                        action:nil];

if ([UINavigationBar instancesRespondToSelector:@selector(setBackIndicatorImage:)]) {
    [[UINavigationBar appearance] setBackIndicatorImage:[[UIImage alloc] init]];
    [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[[UIImage alloc] init]];
}
查看更多
beautiful°
6楼-- · 2019-01-22 20:33

You can hide backbutton

 self.navigationItem.hidesBackButton=YES;

To create custom leftbarbutton you can use this:

UIButton* someButton = [UIButton buttonWithType:UIButtonTypeCustom];
[someButton setFrame:frame];
[someButton setBackgroundImage:@"youArroImageName" forState:UIControlStateNormal];
[someButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[someButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem* someBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:someButton];
[self.navigationItem setLeftBarButtonItem:someBarButtonItem];
查看更多
唯我独甜
7楼-- · 2019-01-22 20:34

Why can't you try with the Custom UIButton :

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(0.0f, 0.0f, 25.0f, 40.0f)];
    [btn addTarget:self action:@selector(buttonEN:) forControlEvents:UIControlEventTouchUpInside];
    [btn setImage:[UIImage imageNamed:@"back-btn"] forState:UIControlStateNormal];
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.backBarButtonItem = backBtn;
查看更多
登录 后发表回答