gpt4 book ai didi

ios - setImage forState 方法为按钮上的所有状态设置图像

转载 作者:技术小花猫 更新时间:2023-10-29 11:18:55 25 4
gpt4 key购买 nike

我有一个我无法解决的小问题。我有大约 16 个按钮,它们作为 socket 集合连接到我的 Controller 。它们还有一个操作方法,可以使按钮的状态从默认状态更改为选中状态。我试图将所有按钮的图像更改为仅默认状态。所以我在数组中运行一个循环,并使用 setImage: forState: 方法将它们的图像设置为默认状态。然而,该方法会更改所有状态(默认和选定状态)的图像。

这是我的 outlet 集合的 setter 方法

- (void) setCardsButton:(NSArray *)cardsButton
{
_cardsButton = cardsButton;

for (UIButton *button in cardsButton) {

[button setImage:[UIImage imageNamed:@"card.png"] forState:UIControlStateNormal];

}
[self updateView];

}

最佳答案

您为“正常”状态设置的任何属性都将用于所有其他未明确设置的状态。这在 UIButton setImage:forState: 的文档中有说明。如果你想为其他州使用不同的图像,你也需要为其他州调用 setImage:forState:

关于ios - setImage forState 方法为按钮上的所有状态设置图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17265001/

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