gpt4 book ai didi

ios - 按下时 UIButton 变淡

转载 作者:行者123 更新时间:2023-11-29 10:37:26 28 4
gpt4 key购买 nike

我已将我的 UIButton 正常状态设置为一个图像,并将它的突出显示状态设置为另一个图像。正常按钮很好,但是当我按下按钮时,它会将其设置为应该是图像的灰色褪色版本。在下图中,顶部的灰色按钮被按下,其他按钮处于正常状态。按钮是通过编程制作的。

UIButton *button;

UIImage *bluenormalImage = [UIImage imageNamed:@"bluebuttonnormal.png"];
UIImage *bluepressedImage = [UIImage imageNamed:@"bluebuttonpushed.png"];

[button setBackgroundImage:bluenormalImage forState:UIControlStateNormal];
[button setBackgroundImage:bluepressedImage forState:UIControlStateHighlighted];

top button is clicked

最佳答案

好吧,我没有意识到文字不是图像的一部分。改为这样做:

据我所知,您需要将按钮正确初始化为自定义类型。当按钮类型为系统时,会出现突出显示问题。

将您的按钮变量行更改为以下内容:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

如果你稍后初始化它,你可以在设置背景图像之前执行以下操作。

UIButton *button 
button = [UIButton buttonWithType:UIButtonTypeCustom];

关于ios - 按下时 UIButton 变淡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26208408/

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