UI控件闪灯

Posted 无梦为安

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UI控件闪灯相关的知识,希望对你有一定的参考价值。

做出点一个控件然后他和他上下左右的4个控件一起变色。

 

#import "ViewController.h"
@interface ViewController ()


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //每个方块的高度和宽度
   CGFloat width=50    ;
    CGFloat height=50;
    //列数
    int lie=5;
    //一行之中的方块间隙
    CGFloat Xjianxi=(self.view.frame.size.width-width*lie)/(lie +1);
    //一列之中的方块间隙
    CGFloat Yjianxi=30;
    self.number=1;
    //循环,
    for (int i=0; i<45; i++) {
        int hangshu=i/lie;
        int lieshu=i%lie;
        self.butn=[[UIButton alloc]initWithFrame:CGRectMake(Xjianxi+lieshu*(Xjianxi+width), Yjianxi+hangshu*(height+Yjianxi), width, height)];
        self.butn.backgroundColor=[UIColor blueColor];
        self.view.tag=100;
        
        
        
        [self.butn addTarget:self action:@selector(Discoloration:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.butn];
        self.butn.tag=self.number++;
        

        
    }

    
        }



-(void)change
{
    if (self.backgroundColor==[UIColor redColor]) {
        self.backgroundColor=[UIColor blueColor];
    }
    else{
        self.backgroundColor=[UIColor redColor];
    }
}



-(void)Discoloration:(UIButton*)btn
{
//    [[self.view viewWithTag:btn.tag] change];
//    [[self.view viewWithTag:btn.tag-1] change];
//    [[self.view viewWithTag:btn.tag+1] change];
//    [[self.view viewWithTag:btn.tag+5] change];
//    [[self.view viewWithTag:btn.tag-5]change];
    self.butn=btn;
    
    if (self.butn.tag==1) {
        [[self.view viewWithTag:btn.tag ] change];
        [[self.view viewWithTag:btn.tag+1] change];
        [[self.view viewWithTag:btn.tag+5] change];
    }
        else if(self.butn.tag==5)
        {
            [[self.view viewWithTag:btn.tag] change];
            [[self.view viewWithTag:btn.tag-1] change];
            [[self.view viewWithTag:btn.tag+5] change];
        }
        else if(self.butn.tag==41)
        {
            [[self.view viewWithTag:btn.tag] change];
            [[self.view viewWithTag:btn.tag-5] change];
            [[self.view viewWithTag:btn.tag+1] change];
        }
        else if(self.butn.tag==45)
        {
            [[self.view viewWithTag:btn.tag] change];
            [[self.view viewWithTag:btn.tag-1] change];
            [[self.view viewWithTag:btn.tag-5] change];
        }
        else if(self.butn.tag%5==1)
        {
            [[self.view viewWithTag:btn.tag] change];
            [[self.view viewWithTag:btn.tag-5] change];
            [[self.view viewWithTag:btn.tag+1] change];
            [[self.view viewWithTag:btn.tag+5] change];
        }
        else if(self.butn.tag%5==0)
        {
            [[self.view viewWithTag:btn.tag] change];
            [[self.view viewWithTag:btn.tag-5] change];
            [[self.view viewWithTag:btn.tag-1] change];
            [[self.view viewWithTag:btn.tag+5] change];
        }
        else if(self.butn.tag%5==1)
        {
            [[self.view viewWithTag:btn.tag] change];
            [[self.view viewWithTag:btn.tag-5] change];
            [[self.view viewWithTag:btn.tag+1] change];
            [[self.view viewWithTag:btn.tag-5] change];
        }
        else
        {
            [[self.view viewWithTag:btn.tag] change];
            [[self.view viewWithTag:btn.tag-1] change];
            [[self.view viewWithTag:btn.tag+1] change];
            [[self.view viewWithTag:btn.tag-5] change];
            [[self.view viewWithTag:btn.tag+5] change];
        }
    }
    



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

 

以上是关于UI控件闪灯的主要内容,如果未能解决你的问题,请参考以下文章

带有自举程序的日期选择器对齐的问题

从 fragmentActivity 刷新片段 UI

我们可以在活动 xml 中编写 UI 以及在片段 xm 中编写 UI 吗?

如何在叠加出现时禁用主UI?

php 一个短代码片段准备在WooCommerce Thank You页面上输出货件跟踪UI。

arm5718下基于KO驱动程序的led闪灯程序