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

        

    }

     
     
     
     
     
     
  • 相关阅读:
    Maven 那点事儿
    maven pom文件详解
    Maven Missing artifact jar
    JVM调优总结 -Xms -Xmx -Xmn -Xss
    LoadRunner做性能测试 从设计到分析执行
    linux内核参数注释与优化
    tcpdump详解
    [转]Linux服务器上11种网络连接状态 和 TCP三次握手/四次挥手详解
    MSM--Memcached_Session_Manager介绍及使用
    黏性Session和非黏性Session
  • 原文地址:https://www.cnblogs.com/xubojoy/p/3885928.html
Copyright © 2011-2022 走看看