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

        

    }

  • 相关阅读:
    Nginx——基本操作
    JavaWeb——关于RequestDispatcher的原理
    JavaWeb——XML转义符字
    JavaWeb——JSTL 核心标签库使用
    JavaWeb——jsp-config
    URL和URI区别
    Docker入门5------生产力工具docker-compose
    Docker入门4------Dockerfile
    Docker入门3------手动编辑自定义镜像
    Docker入门2------容器container常规操作
  • 原文地址:https://www.cnblogs.com/pruple/p/5255501.html
Copyright © 2011-2022 走看看