gpt4 book ai didi

ios - 在导航栏上添加自定义后退按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:29:20 24 4
gpt4 key购买 nike

我正在尝试在导航栏上添加自定义后退按钮,但它不起作用下面是我的代码

-(void)addLeftButton
{
UIImage *buttonImage = [UIImage imageNamed:@"btn_back.png"];

UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];

[aButton setBackgroundImage:buttonImage forState:UIControlStateNormal];

aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);

UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];

[aButton addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.backBarButtonItem = aBarButtonItem;
}

请告诉我这段代码有什么问题

最佳答案

试试这个。

-(void)addLeftButton
{
UIImage *buttonImage = [UIImage imageNamed:@"btn_back.png"];

UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];

[aButton setBackgroundImage:buttonImage forState:UIControlStateNormal];

aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);

UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];

[aButton addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];

[self.navigationItem setLeftBarButtonItem:aBarButtonItem];
}

关于ios - 在导航栏上添加自定义后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19721097/

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