概述
NSArray *buttonTitleAry=[[NSArray alloc]initWithObjects:@"全部",@"待支付",@"已支付",@"已退款",nil];
buttonArray=[[NSMutableArray alloc]init];
//循环创建Button
for (int i=0; i<buttonTitleAry.count; i++) {
//按钮位置
CGRect frame=CGRectMake(10+i*buttonWidth4, 0.2*topHeight, buttonWidth4-20, topHeight*0.6);
UIButton *button=[UIButton buttonWithType:UIButtonTypeSystem];
[button addTarget:self action:@selector(Onclick:)forControlEvents:UIControlEventTouchUpInside];
[button setTitle:[NSString stringWithFormat:@"%@",buttonTitleAry[i]]forState:UIControlStateNormal];
button.backgroundColor=[UIColor clearColor];
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
button.frame=frame;
button.tag=i;
button.layer.cornerRadius=button.frame.size.width/9;
[topView addSubview:button];
if(i==0)
{
button.backgroundColor=[UIColor colorWithRed:0 green:166/255.0f blue:154/255.0f alpha:1];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
[buttonArray addObject:button];
}
//button点击事件
-(void)Onclick:(id)sender
{
NSInteger tag=[sender tag];
for (int i=0; i<buttonArray.count; i++) {
UIButton *button=(UIButton *)buttonArray[i];
button.backgroundColor=[UIColor clearColor];
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
if(i==tag)
{
button.backgroundColor=[UIColor colorWithRed:0 green:166/255.0f blue:154/255.0falpha:1];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}
}
最后
以上就是风趣樱桃为你收集整理的button点击效果的全部内容,希望文章能够帮你解决button点击效果所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复