利用UIView做出霓虹灯的效果

效果如图


代码如下(只有实现部分)

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];
    
    // 定义view,颜色模块
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 340, 340)];
    view1.backgroundColor = [UIColor greenColor];
    [self.window addSubview:view1];
    [view1 release];
    view1.tag = 1;
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(40, 40, 300, 300)];
    view2.backgroundColor = [UIColor purpleColor];
    [self.window addSubview:view2];
    [view2 release];
    view2.tag = 2;

    
    UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(60, 60, 260, 260)];
    view3.backgroundColor = [UIColor magentaColor];
    [self.window addSubview:view3];
    [view3 release];
    view3.tag = 3;

    
    UIView *view4 = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 220, 220)];
    view4.backgroundColor = [UIColor redColor];
    [self.window addSubview:view4];
    [view4 release];
    view4.tag = 4;

    
    UIView *view5 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 180, 180)];
    view5.backgroundColor = [UIColor orangeColor];
    [self.window addSubview:view5];
    [view5 release];
    view5.tag = 5;

    
    UIView *view6 = [[UIView alloc] initWithFrame:CGRectMake(120, 120, 140, 140)];
    view6.backgroundColor = [UIColor yellowColor];
    [self.window addSubview:view6];
    [view6 release];
    view6.tag = 6;

    
    UIView *view7 = [[UIView alloc] initWithFrame:CGRectMake(140, 140, 100, 100)];
    view7.backgroundColor = [UIColor cyanColor];
    [self.window addSubview:view7];
    [view7 release];
    view7.tag = 7;

    // 定义一个timer,实现色块变化
     NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(changeColor) userInfo:nil repeats:YES];
    
    return YES;
}

- (void)changeColor
{
    // 定义一个color来接收7的颜色
    UIColor *color = [self.window viewWithTag:7].backgroundColor;
    // 换颜色
    for (int i = 6 ; i > 0; i--) {
        [self.window viewWithTag:i + 1].backgroundColor = [self.window viewWithTag:i ].backgroundColor;
    }
    // 最里面给最外面
    [self.window viewWithTag:1].backgroundColor = color;
}
@end


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值