zoukankan      html  css  js  c++  java
  • UIButton 关灯小实验

    // 写在继承于UIViewController的子类中:创建单视图默认有ViewController类

    // 实现:点击任何一颗UIButton,它四周的以及它自身都被变成红色,再点击就会变成原来的灰色

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        

        NSInteger numi = 15, i = 0, j = 0;

        for (; i<13; i++)

        {

            NSInteger numj = 30; j = 0;

            for (; j<23; j++)

            {

                UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(numi+i*30, numj+j*30, 20, 20)];

                button.layer.cornerRadius = 10;

                button.backgroundColor = [UIColor grayColor];

                [self.view addSubview:button];

                [button addTarget:self action:@selector(buttonclik:) forControlEvents:UIControlEventTouchUpInside];

                

                // 给button.tag编号

                button.tag = 101 + i + 13 * j;

            }

        }

    }

    - (void)buttonclik:(UIButton *)button;

    {

         NSInteger arr[5] = {button.tag, button.tag+13, button.tag-13, button.tag-1, button.tag+1};

        for (int i = 0; i < 23; i++)

        {

            if (button.tag==101+13*i)

            {

                arr[3] = 100;

            }

            if (button.tag==113+13*i)

            {

                arr[4] = 100;

            }

        }

        

        for (int i = 0; i < 5; i++)

        {

            UIButton *temB = [self.view viewWithTag:arr[i]];

            if (temB.backgroundColor == [UIColor grayColor])

                    {

                        temB.backgroundColor = [UIColor redColor];

                    }else

                    {

                        temB.backgroundColor = [UIColor grayColor];

                    }

        }

        

        NSLog(@"%lu", button.tag);

        

    }

  • 相关阅读:
    P4995 跳跳!
    P4306 [JSOI2010]连通数
    P1339 [USACO09OCT]热浪Heat Wave
    P2002 消息扩散
    P3388 【模板】割点(割顶)
    P1656 炸铁路
    P2863 [USACO06JAN]牛的舞会The Cow Prom
    P1516 青蛙的约会
    3.从尾到头打印链表
    2.替换空格
  • 原文地址:https://www.cnblogs.com/pruple/p/5255501.html
Copyright © 2011-2022 走看看