您的位置:首页 > 产品设计 > UI/UE

button实现类似uisegment效果

2012-12-12 23:04 381 查看
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 image:@"buttonCommon.png" select:@selector(touch:) who:self];
//给button添加tag值
button.tag=i+1;
if (button.tag==1)
{
[button setBackgroundImage:[UIImage imageNamed:@"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 imageNamed:@"buttonCommon.png"] forState:UIControlStateNormal];
}
[button setBackgroundImage:[UIImage imageNamed:@"buttonSelect.png"] forState:UIControlStateNormal];
}

本文出自 “yangjun” 博客,请务必保留此出处http://yang120jun.blog.51cto.com/3199830/1087569
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: