gpt4 book ai didi

ios - 标题未显示在 UIButton 上

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:57:11 26 4
gpt4 key购买 nike

我将以下代码用于导航栏中带有标题的自定义后退按钮。但是,没有显示标题,有什么帮助吗?

注意:后退按钮图像是黑色的,与 ios 默认使用的图像相同,需要自定义操作处理程序,这就是为什么要这样做。

backButton=[UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateSelected];
[backButton addTarget:self action:@selector(customBack) forControlEvents:UIControlEventTouchUpInside];
[backButton setFrame:CGRectMake(0,0,64,32)];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[backButton setTitle:@"Encameo" forState:UIControlStateNormal];
[backButton setTitle:@"Encameo" forState:UIControlStateSelected];

self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView: backButton];

最佳答案

你在按钮上设置图像而不是这个你需要设置 UIButton 的 backgroundImage 然后你的标题将被显示。

这样修改代码

backButton=[UIButton buttonWithType:UIButtonTypeCustom];
[backButton setBackgroundImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateNormal];
[backButton setBackgroundImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateSelected];
[backButton addTarget:self action:@selector(customBack) forControlEvents:UIControlEventTouchUpInside];
[backButton setFrame:CGRectMake(0,0,64,32)];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[backButton setTitle:@"Encameo" forState:UIControlStateNormal];
[backButton setTitle:@"Encameo" forState:UIControlStateSelected];

self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView: backButton];

关于ios - 标题未显示在 UIButton 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6765359/

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