iOS 霓虹灯效果(同种颜色依次向外扩展)

这篇博客介绍了如何在iOS应用中实现霓虹灯效果,通过创建不同颜色的UIView,并使用NSTimer定时改变背景颜色,从红色开始依次向外扩展,形成类似霓虹灯的视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#import "ZXHAppDelegate.h"

<span style="font-size:18px;">@implementation ZXHAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    
    
    /*
    NSArray *arr = [NSArray arrayWithObjects:[UIColor redColor],[UIColor orangeColor],
[UIColor yellowColor],
[UIColor greenColor],[UIColor cyanColor],[UIColor blueColor],
[UIColor purpleColor], nil];
    for (NSInteger i = 0; i < 7; i ++) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0 + i * 20, 0 + i *20,
 320 - 40 * i , 568 - i * 40)];
        view.backgroundColor = arr[random()%6];
        
        [self.window addSubview:view];
        [view release];
}
     */

    //红色视图
    UIView *redView=[[UIView alloc] initWithFrame:CGRectMake(0, 153, 320, 320)];
    redView.backgroundColor=[UIColor redColor];
    redView.tag = 101;
    [self.window addSubview:redView];
    [redView release];
    
    
    //橙色视图
    UIView *oriangeView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, 280)];
    oriangeView.backgroundColor=[UIColor orangeColor];
    oriangeView.tag = 102;
    [redView addSubview:oriangeView];
    [oriangeView release];
    
    //黄色视图
    UIView *yellowView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 240, 240)];
    yellowView.backgroundColor=[UIColor yellowColor];
    yellowView.tag = 103;
    [oriangeView addSubview:yellowView];
    [yellowView release];
    
    
    //绿色视图
    UIView *greenView=[[UIView alloc] initWithFrame:CGRectMake(20,20, 200, 200)];
    greenView.backgroundColor=[UIColor greenColor];
    greenView.tag = 104;
    [yellowView addSubview:greenView];
    [greenView release];
    
    //青色视图
    UIView *cyanView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 160, 160)];
    cyanView.backgroundColor=[UIColor cyanColor];
    cyanView.tag = 105;
    [greenView addSubview:cyanView];
    [cyanView release];
    
    //蓝色视图
    UIView *blueView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 120, 120)];
    blueView.backgroundColor=[UIColor blueColor];
    blueView.tag = 106;
    [cyanView addSubview:blueView];
    [blueView release];
    
    //紫色视图
    
    UIView *purpleView=[[UIView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)];
    purpleView.backgroundColor=[UIColor purpleColor];
    purpleView.tag = 107;
    [blueView addSubview:purpleView];
    [purpleView release];

    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(Ltime) 
userInfo:nil repeats:YES];
    
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}


- (void)Ltime
{
    UIColor *temp = [self.window viewWithTag:101].backgroundColor;
    for (int i = 0; i < 6; i++) {
        [self.window viewWithTag:101 + i].backgroundColor = 
[self.window viewWithTag:102 + i].backgroundColor;
    }
    [self.window viewWithTag:107].backgroundColor = temp;
}</span>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值