for (int i=0; i<array.count; i++)
{
//循环添加button
UIButton * button = [custombutton initbutton:CGRectMake(i*80, 0, 80, 30) title:[[array objectAtIndex:i] valueForKey:@”typeName”]font:12 p_w_picpath:@”buttonCommon.png” select:@selector(touch:) who:self];
//给button添加tag值
button.tag=i+1;
if (button.tag==1)
{
[button setBackgroundImage:[UIImage p_w_picpathNamed:@”buttonSelect.png”] forState:UIControlStateNormal];
}
[scro addSubview:button];
}
-(void)touch:(id)sender
{ UIButton * button = (UIButton*)sender;
//点击button更改背景
for (int i=0; i<array.count; i++)
{ //通过tag值取到button
UIButton * butt =(UIButton *)[scro viewWithTag:i+1];
[butt setBackgroundImage:[UIImage p_w_picpathNamed:@”buttonCommon.png”] forState:UIControlStateNormal];
}
[button setBackgroundImage:[UIImage p_w_picpathNamed:@”buttonSelect.png”] forState:UIControlStateNormal];
}
转载于:https://blog.51cto.com/yang120jun/1087569
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/110259.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...