[英]iphone uibutton: I want to change the UIControlStateNormal image
我创建了一个UIButton
数组。 我需要在各个时间以编程方式更改这些按钮上的图像。 为了使此功能暂时起作用,我想在按下按钮时更改图像,但这不是真正发生的时间。
因此,我创建了一个按钮数组,并将它们排列在屏幕上的网格上:
for (UInt16 index=0; index < (mNumColumns * mNumRows); index++)
{
<....Snipped code for setting the x,y,width,height vars...>
UIButton *thisCell = [UIButton buttonWithType:UIButtonTypeCustom];
thisCell.tag = index;
thisCell.frame = CGRectMake(currentX, currentY, cellWidth, cellHeight);
[thisCell addTarget:self action:@selector(buttonPushed:)
forControlEvents:UIControlEventTouchUpInside];
[thisCell setImage:[UIImage imageNamed:@"cellBackground.png"]
forState:UIControlStateNormal];
[[self view] addSubview:thisCell];
}
-然后是按钮处理程序-
-(void)buttonPushed:(UIView*)clickedButton
{
NSLog(@"Click %d", clickedButton.tag);
[clickedButton setImage:[UIImage imageNamed:@"cellEmpty.png"]
forState:UIControlStateNormal];
[clickedButton setNeedsDisplay];
}
1)初始按钮网格显示正确。
2)如果将初始网格的PNG的文件名更改为cellEmpty.png,它将与新图像一起使用,因此我知道该图像可以显示。
3)我在调试器中看到“ Click n”,因此正确的按钮正在调用buttonPushed
但是,您可以猜测,该图像没有更新。 我不认为我现在不想处理按钮状态....因为图像更改实际上与现实生活中的按钮获取压力无关(更改将是通过网络下载新图像的结果)。
谢谢你的帮助。 我需要弄清楚这里还有其他有趣的事情。 创建按钮的视图是选项卡栏上的框架,如果我将选项卡栏更改为另一个视图并返回,则图像已更新。
找出答案后,我将更新答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.