How to change UINavigation Back Button to an image?

安稳与你 提交于 2019-12-04 18:03:12
mr.boyfox

If you want add back button to UINavigation try this:

First create back button:

1. If you don`t need back action:

        UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"
        style:UIBarButtonItemStyleDone target:nil action:nil];

2. If you want create back button with image try this:

    UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage
    imageNamed:@"yourImageName"] style:UIBarButtonItemStylePlain target:nil
    action:nil]

3. If you want create back button with image and action try this:

    UIBarButtonItem *myBackButton = [[UIBarButtonItem alloc] initWithImage:[UIImage
    imageNamed:@"yourImageName"] style:UIBarButtonItemStylePlain target:self
    action:@selector(goBack:)]

    - (void)goBack:(id)sender {
        [self.navigationController popViewControllerAnimated:YES];
    }

After created back button add its to NavigationBar:

self.navigationItem.backBarButtonItem = myBackButton;

Add back button code you can implement in viewDidLoad method:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.backBarButtonItem = myBackButton;
}

And you need more information see this: UIBarButtonItem Class Reference

Here more examples to you:


art-divin

Here is how you can do this:

UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleBordered target:target action:action;]
self.navigationItem.rightButtonItem = back;

For more info about UIBarButtonItem, go here.

Also try to search next time for similar questions before posting new.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!