霓虹灯


AppDelegate.m文件


//

//  AppDelegate.m

//  UI_2_HomeWork

//

//  Created by 0101 on 13-7-28.

//  Copyright (c) 2013 PH. All rights reserved.

//


#import "AppDelegate.h"

#import "Neon.h"


@implementation AppDelegate


- (void)dealloc

{

    [_window release];

    [super dealloc];

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    self.window.backgroundColor = [UIColor whiteColor];

    

    

    Neon *h = [[Neon alloc]init];

    self.window.rootViewController = h;

    [h release];

    

    [self.window makeKeyAndVisible];

    return YES;

}



Neon.m文件

//

//  Neon.m

//  UI_2_HomeWork

//

//  Created by 0101 on 13-7-28.

//  Copyright (c) 2013 PH. All rights reserved.

//


//霓虹灯


#import "Neon.h"

#define KFrame(x,y,w,h) CGRectMake(x,y,w,h)

@implementation Neon


//加载视图

-(void)loadView

{

    //初始化根视图 方式一,这种方式效率更高

    self.view = [[[UIView alloc]initWithFrame:KFrame(0, 0, 320, 480)]autorelease];

    

    //将颜色存储在数组中

    arrColor = [[NSMutableArray alloc]initWithObjects:

                                    [UIColor redColor],

                                    [UIColor blueColor],

                                    [UIColor yellowColor],

                                    [UIColor purpleColor],

                                    nil];

    //使用for循环连续创建四个view

    for (int i = 0 ; i < 4 ; i++ )

    {

        UIView *aView = [[UIView alloc]initWithFrame:KFrame(i*50+10, 50, 50, 50)];

        aView.tag = i + 1000;

        aView.backgroundColor = [UIColor whiteColor];

        [self.view addSubview:aView];

        [aView release];

    }

    

    //创建一个定时器用于连续的改变颜色

    NSTimer *time = [NSTimer scheduledTimerWithTimeInterval:0.5

                                                     target:self

                                                   selector:@selector(changeColor:)

                                                   userInfo:nil

                                                    repeats:YES];

    

    

}


//改变颜色消息

-(void)changeColor:(NSTimer *)aTimer

{

    //aView依据Tag赋给bView

    for (int i = 0 ; i < 4 ; i++)

    {

        UIView *bView = [self.view viewWithTag:1000 + i];

        //arrColor中的颜色对象赋给bView.backgroundColor

        bView.backgroundColor = [arrColor objectAtIndex:i];

    }

    //创建一个新的颜色对象,并将arrColor中最后一个颜色赋给newColor

     UIColor *newColor = [arrColor lastObject];

    //为防止arrColor数组不断的增大应删除最后一个对象,使数组总保持四个对象的容量

    [arrColor removeLastObject];

    //同时将最后一个对象插入到最前面

    [arrColor insertObject:newColor atIndex:0];

}


-(void)viewDidLoad

{

    

}


-(void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}

@end



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值