gpt4 book ai didi

ios - 如何设置自定义 View 后退按钮

转载 作者:行者123 更新时间:2023-11-29 12:44:55 26 4
gpt4 key购买 nike

在 View Controller A 中,在 viewDid Load 中我有这个:

UIImage * backButtonImage = [UIImage imageNamed: @"bar-arrow"];
UIBarButtonItem* b = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = b;

仍然在下一个 View Controller 的导航中。酒吧我明白了:

enter image description here

换句话说——IOS7原来的后退箭头仍然显示。无法摆脱它!!

最佳答案

通常隐藏 NativationBar 的默认后退按钮:

[self.navigationItem setHidesBackButton:YES animated:YES];   
[self.navigationItem setHidesBackButton:YES];

并执行以下代码:

    UIButton *BackButton =  [UIButton buttonWithType:UIButtonTypeCustom];
[BackButton setImage:[UIImage imageNamed:@"bar-arrow"] forState:UIControlStateNormal];
[BackButton addTarget:self action:@selector(prevButtonAction)forControlEvents:UIControlEventTouchUpInside];
[BackButton setFrame:CGRectMake(0, 0, 12, 20)];// set as par your need


UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:BackButton];
self.navigationItem.leftBarButtonItem = barButton;


-(void)prevButtonAction
{
[self.navigationController popViewControllerAnimated:YES];
}

关于ios - 如何设置自定义 View 后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23889766/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com