zoukankan      html  css  js  c++  java
  • 可实现随意切换的button同时随切换改变title的颜色

    -(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);

        

    }

     
     
     
     
     
     
  • 相关阅读:
    安装包安装服务,点修复出现的错误”Error 1001:指定的服务已存在“ 解决办法
    C# tostring 格式化输出 (转)
    WPF button 如何区分click和doubleclick
    二叉树算法
    关于OA流程相关数据表的设计
    没事干写写流程审批数据库的设计
    挂载system.img并提取文件
    使Checkbox禁用,不可选
    Android显示网速的另一种方法
    C语言 解压华为固件
  • 原文地址:https://www.cnblogs.com/xubojoy/p/3885928.html
Copyright © 2011-2022 走看看