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

        

    }

  • 相关阅读:
    SQL的Demo 由Access改为SQLite
    Delphi10.3ComboBoxEx下拉左边带图标
    uniGUI学习之IconCombobox(53)
    MySQL的图形GUI界面Navicat操作(03)
    delphi10.3安装使用mySQL(02)从SQLite 转移至Mysql
    [转] Java虚拟机原理图解 系列
    [转]ASM插入代码 visitFieldInsn
    [转]大话+图说:Java字节码指令——只为让你懂
    [转]smali语言之locals和registers的区别
    [转]Smali浅析及dex,java互转
  • 原文地址:https://www.cnblogs.com/pruple/p/5255501.html
Copyright © 2011-2022 走看看