码迷,mamicode.com
首页 > 其他好文 > 详细

可实现随意切换的button同时随切换改变title的颜色

时间:2014-08-01 23:03:02      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:color   使用   io   for   cti   ar   div   log   

-(void)addBtn

{      

    NSArray *arr = [[NSArray alloc] initWithObjects:@"未使用",@"已使用",@"已付款",@"退款", nil];

    for (int i = 0; i < 4; i ++) {

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        btn.frame = CGRectMake(16+i*(60+16), 40, 60, 44);

        btn.tag = 10+i;

        [btn setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];

        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];

        

        if (btn.tag==10) {

            [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

        }

        [self addSubview:btn];

    }

    

    

    

    

}

 

-(void)btnClick:(UIButton *)sender

{

    static int currentSelectButtonIndex = 0;

    static int previousSelectButtonIndex=10;

    

    currentSelectButtonIndex=sender.tag;

    UIButton *previousBtn=(UIButton *)[self viewWithTag:previousSelectButtonIndex];

    

    [previousBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    

    

    UIButton *currentBtn = (UIButton *)[self viewWithTag:currentSelectButtonIndex];;

    [currentBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

    previousSelectButtonIndex=currentSelectButtonIndex;

 

    NSLog(@">>>>>>>>>%d",currentSelectButtonIndex);

    

}

 
 
 
 
 
 

可实现随意切换的button同时随切换改变title的颜色,布布扣,bubuko.com

可实现随意切换的button同时随切换改变title的颜色

标签:color   使用   io   for   cti   ar   div   log   

原文地址:http://www.cnblogs.com/xubojoy/p/3885928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!