gpt4 book ai didi

iphone - 单击按钮时如何更改表格 View 中的按钮图像

转载 作者:行者123 更新时间:2023-12-03 21:20:59 25 4
gpt4 key购买 nike

我需要在 UItableview 中放置一个复选框。

为此,我放置了一个框,没有检查图像是否放置在按钮上。

我的代码是,

UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
customButton.frame=CGRectMake(100, 10, 100, 100);
[customButton setImage:[UIImage imageNamed:@"unselected.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:customButton];

现在我需要在单击按钮时更改按钮图像。

我在哪里可以做到这一点。

我怎样才能刺穿这个。

谁能帮帮我吗?

提前谢谢你。

最佳答案

//add this line
[customButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

//then
-(void) buttonClicked:(id) sender
{
UIButton * button = (UIButton*) sender;
[button setImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateNormal];

}

关于iphone - 单击按钮时如何更改表格 View 中的按钮图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4812804/

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