gpt4 book ai didi

ios - 点击时 UIButton 图像不会改变

转载 作者:行者123 更新时间:2023-11-29 03:23:18 27 4
gpt4 key购买 nike

我需要在点击图像按钮时将其更改为不同的图像。很简单,那里有样本,但它们不适合我。这是我按照示例尝试的:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(20, 270, 200, 40.0);
[button setImage:[UIImage imageNamed:@"butterfly3.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"clicked.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
[button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Submit" forState:UIControlStateNormal];
[scrollView button];

现在,我注意到我的按钮设置为在 UIControlEventTouchDown 上执行它的操作,所以我将它添加到“已单击”控件状态,如下所示:

[button setImage:[UIImage imageNamed:@"clicked.png"] forState:UIControlStateSelected | UIControlStateHighlighted | UIControlEventTouchDown];

但图像仍然保持不变。我错过了什么?

最佳答案

只需按此更改您的代码,一切都会正常!

[button setImage:[UIImage imageNamed:@"clicked.png"] forState:UIControlStateHighlighted];
[button setImage:[UIImage imageNamed:@"clicked.png"] forState:UIControlStateSelected];

关于ios - 点击时 UIButton 图像不会改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20801819/

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