gpt4 book ai didi

iphone - 使用自定义图像和文本颜色更改后退按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:46:39 54 4
gpt4 key购买 nike

我想更改导航栏中后退按钮的后退按钮外观。为此,我有这段代码。

UIImage *backButtonImage = [UIImage imageNamed:@"backbutton.png"];
UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
backbutton.backgroundColor = [UIColor colorWithPatternImage:backButtonImage];
backbutton.titleLabel.text = @"back";
backbutton.titleLabel.textColor= [UIColor colorWithRed:50/255.0
green:158/255.0
blue:218/255.0
alpha:1.0];

backbutton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);
UIBarButtonItem * back = [[UIBarButtonItem alloc] initWithCustomView:backbutton];
[backbutton addTarget:self action:@selector(back_Clicked) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = back;

但我仍然得到标准的后退按钮。有什么帮助吗?

最佳答案

在将该 viewController 推送到堆栈之前,将您的代码用于自定义后退按钮。并设置 BackBarButtonItem ,而不是 leftBarButtonItem。

UIImage *image = [UIImage imageNamed:@"backbutton.png"];
UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
backbutton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[backbutton setImage:image forState:UIControlStateNormal];
backbutton.titleLabel.textColor = [UIColor blueColor];
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:backbutton];
[[self navigationItem] setBackBarButtonItem: back];
[self.navigationController pushViewController:yourViewControllerObject animated:YES];

关于iphone - 使用自定义图像和文本颜色更改后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13856363/

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