首页 > 代码库 > OC实现简单的霓虹灯功能

OC实现简单的霓虹灯功能

//比较简单的动态效果,仅仅由内到外不能换向,颜色是随机生成的

//随机生成7中颜色

<span style="font-size:18px;"> for (int i = 0;i < 7;i++) {
        _view = [[UIView alloc]initWithFrame:CGRectMake((20 + i * 20), (114 + i * 20 ),280 - (i * 40) ,280 - (i * 40))];
        _view.tag = 100 + i;
        _view.backgroundColor = [UIColor colorWithRed:((arc4random() % 256) / 255.0) green:(arc4random() % 256) / 255.0 blue:(arc4random() % 256) / 255.0 alpha:1.0];
               [self.window addSubview:_view];
        [_view release];
    }
</span>
<p class="p1"><span style="font-size:18px;"></span></p>

//设置timer

<span style="font-size:18px;">[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(change) userInfo:nil repeats:YES];</span>

//实现timer
<span style="font-size:18px;">- (void)change
{
    
    UIColor *color1  = [self.window viewWithTag:100].backgroundColor;
    for (int i = 100; i < 106; i++) {
        [self.window viewWithTag:i].backgroundColor = [self.window viewWithTag:i + 1].backgroundColor;
    }
    [self.window viewWithTag:106].backgroundColor = color1;


}</span>
上传的图片没动态效果...