首先创建一个视图NioLampViewController类

AppDelegate.h

#import<UIKit/UIKit.h>@interfaceAppDelegate:UIResponder<UIApplicationDelegate>@property(strong,nonatomic)UIWindow*window;@end

AppDelegate.m

#import"AppDelegate.h"#import"NioLampViewController.h"@implementationAppDelegate-(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions{self.window=[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];//Overridepointforcustomizationafterapplicationlaunch.self.window.backgroundColor=[UIColorwhiteColor];[self.windowmakeKeyAndVisible];//创建并且指定一个控制器NioLampViewController*mainVC=[[NioLampViewControlleralloc]init];self.window.rootViewController=mainVC;[_windowrelease];returnYES;}-(void)dealloc{[_windowrelease];[superdealloc];}-(void)applicationWillResignActive:(UIApplication*)application{//Sentwhentheapplicationisabouttomovefromactivetoinactivestate.Thiscanoccurforcertaintypesoftemporaryinterruptions(suchasanincomingphonecallorSMSmessage)orwhentheuserquitstheapplicationanditbeginsthetransitiontothebackgroundstate.//Usethismethodtopauseongoingtasks,disabletimers,andthrottledownOpenGLESframerates.Gamesshouldusethismethodtopausethegame.}-(void)applicationDidEnterBackground:(UIApplication*)application{//Usethismethodtoreleasesharedresources,saveuserdata,invalidatetimers,andstoreenoughapplicationstateinformationtorestoreyourapplicationtoitscurrentstateincaseitisterminatedlater.//Ifyourapplicationsupportsbackgroundexecution,thismethodiscalledinsteadofapplicationWillTerminate:whentheuserquits.}-(void)applicationWillEnterForeground:(UIApplication*)application{//Calledaspartofthetransitionfromthebackgroundtotheinactivestate;hereyoucanundomanyofthechangesmadeonenteringthebackground.}-(void)applicationDidBecomeActive:(UIApplication*)application{//Restartanytasksthatwerepaused(ornotyetstarted)whiletheapplicationwasinactive.Iftheapplicationwaspreviouslyinthebackground,optionallyrefreshtheuserinterface.}-(void)applicationWillTerminate:(UIApplication*)application{//Calledwhentheapplicationisabouttoterminate.Savedataifappropriate.SeealsoapplicationDidEnterBackground:.}@end

NioLampViewController.h

#import<UIKit/UIKit.h>@interfaceNioLampViewController:UIViewController@end

NioLampViewController.m

#import"NioLampViewController.h"@interfaceNioLampViewController()@end@implementationNioLampViewController-(id)initWithNibName:(NSString*)nibNameOrNilbundle:(NSBundle*)nibBundleOrNil{self=[superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];if(self){//Custominitialization}returnself;}-(void)viewDidLoad{[superviewDidLoad];//Doanyadditionalsetupafterloadingtheview.self.view.backgroundColor=[UIColorwhiteColor];UIView*view1=[[UIViewalloc]initWithFrame:CGRectMake(20,50,280,280)];view1.backgroundColor=[UIColoryellowColor];view1.layer.cornerRadius=140;view1.tag=100;[self.viewaddSubview:view1];[view1release];UIView*view2=[[UIViewalloc]initWithFrame:CGRectMake(40,70,240,240)];view2.backgroundColor=[UIColormagentaColor];view2.layer.cornerRadius=120;view2.tag=250;[self.viewaddSubview:view2];[view2release];UIView*view3=[[UIViewalloc]initWithFrame:CGRectMake(60,90,200,200)];view3.backgroundColor=[UIColorblueColor];view3.layer.cornerRadius=100;view3.tag=300;[self.viewaddSubview:view3];[view3release];UIView*view4=[[UIViewalloc]initWithFrame:CGRectMake(80,110,160,160)];view4.backgroundColor=[UIColorredColor];view4.layer.cornerRadius=80;view4.tag=400;[self.viewaddSubview:view4];[view4release];UIView*view5=[[UIViewalloc]initWithFrame:CGRectMake(100,130,120,120)];view5.backgroundColor=[UIColordarkGrayColor];view5.layer.cornerRadius=60;view5.tag=500;[self.viewaddSubview:view5];[view5release];UIView*view6=[[UIViewalloc]initWithFrame:CGRectMake(120,150,80,80)];view6.backgroundColor=[UIColororangeColor];view6.layer.cornerRadius=40;view6.tag=600;[self.viewaddSubview:view6];[view6release];UIView*view7=[[UIViewalloc]initWithFrame:CGRectMake(140,170,40,40)];view7.backgroundColor=[UIColorblackColor];view7.layer.cornerRadius=20;view7.tag=700;[self.viewaddSubview:view7];[view7release];[NSTimerscheduledTimerWithTimeInterval:0.5target:selfselector:@selector(timerFired)userInfo:nilrepeats:YES];//NSTimer*myTimer=[NSTimertimerWithTimeInterval:1.0target:selfselector:@selector(timerFired)userInfo:nilrepeats:YES];//[myTimerfire];////NSTimer*timer=[NSTimertimerWithTimeInterval:0.3target:selfselector:@selector(timerFired)userInfo:nilrepeats:YES];//[[NSRunLoopcurrentRunLoop]addTimer:timerforMode:NSDefaultRunLoopMode];//for(inti=0;i<7;i++){////UIView*view=[[UIViewalloc]initWithFrame:CGRectMake(0+i*20,0+i*20,320-40*i,568-i*40)];////CGFloatcolor=(arc4random()%256/255.0);////CGFloatsaturation=(arc4random()%128/256.0)+0.5;////CGFloatbrightness=(arc4random()%128/256.0)+0.5;//CGFloatbrightness1=(arc4random()%56/256.0)+0.5;////view.backgroundColor=[UIColorcolorWithHue:colorsaturation:saturationbrightness:brightnessalpha:brightness1];////[self.viewaddSubview:view];////[viewrelease];////}//CGFloatcolor=(arc4random()%256/255.0);////CGFloatsaturation=(arc4random()%128/256.0)+0.5;////CGFloatbrightness=(arc4random()%128/256.0)+0.5;//CGFloatbrightness1=(arc4random()%56/256.0)+0.5;//view.backgroundColor=[UIColorcolorWithHue:colorsaturation:saturationbrightness:brightnessalpha:brightness1]////NSArray*array=[NSArrayarrayWithObjects:[UIColorredColor],[UIColororangeColor],[UIColoryellowColor],[UIColorgreenColor],[UIColorblueColor],[UIColorcyanColor],[UIColorpurpleColor],nil];//方块for(inti=0;i<11;i++){UIView*view=[[UIViewalloc]initWithFrame:CGRectMake(100+i*5,340+i*5,100-i*10,100-i*10)];CGFloatcolor=(arc4random()%256/255.0);CGFloatsaturation=(arc4random()%128/256.0)+0.5;CGFloatbrightness=(arc4random()%128/256.0)+0.5;CGFloatbrightness1=(arc4random()%56/256.0)+0.5;view.backgroundColor=[UIColorcolorWithHue:colorsaturation:saturationbrightness:brightnessalpha:brightness1];view.tag=i+200;NSLog(@"%ld",(long)view.tag);[self.viewaddSubview:view];[viewrelease];}[NSTimerscheduledTimerWithTimeInterval:0.5target:selfselector:@selector(roll)userInfo:nilrepeats:YES];//竖条for(inti=0;i<10;i++){UIView*view=[[UIViewalloc]initWithFrame:CGRectMake(300,40+i*40,20,40)];CGFloatcolor=(arc4random()%256/255.0);CGFloatsaturation=(arc4random()%128/256.0)+0.5;CGFloatbrightness=(arc4random()%128/256.0)+0.5;CGFloatbrightness1=(arc4random()%56/256.0)+0.5;view.backgroundColor=[UIColorcolorWithHue:colorsaturation:saturationbrightness:brightnessalpha:brightness1];view.tag=i+2000;NSLog(@"%ld",(long)view.tag);[self.viewaddSubview:view];[viewrelease];}[NSTimerscheduledTimerWithTimeInterval:0.5target:selfselector:@selector(shutiao)userInfo:nilrepeats:YES];}-(void)shutiao{UIColor*temp=[self.viewviewWithTag:200].backgroundColor;for(inti=2000;i<2010;i++){[self.viewviewWithTag:i].backgroundColor=[self.viewviewWithTag:i+1].backgroundColor;}[self.viewviewWithTag:2009].backgroundColor=temp;}-(void)roll{UIColor*temp=[self.viewviewWithTag:200].backgroundColor;for(inti=200;i<211;i++){[self.viewviewWithTag:i].backgroundColor=[self.viewviewWithTag:i+1].backgroundColor;}[self.viewviewWithTag:210].backgroundColor=temp;}-(void)timerFired{UIView*p1=[self.viewviewWithTag:100];UIView*p2=[self.viewviewWithTag:250];UIView*p3=[self.viewviewWithTag:300];UIView*p4=[self.viewviewWithTag:400];UIView*p5=[self.viewviewWithTag:500];UIView*p6=[self.viewviewWithTag:600];UIView*p7=[self.viewviewWithTag:700];//[self.viewviewWithTag:100].backgroundColor=[self.viewviewWithTag:200].backgroundColor;UIColor*temp=p1.backgroundColor;p1.backgroundColor=p2.backgroundColor;p2.backgroundColor=p3.backgroundColor;p3.backgroundColor=p4.backgroundColor;p4.backgroundColor=p5.backgroundColor;p5.backgroundColor=p6.backgroundColor;p6.backgroundColor=p7.backgroundColor;p7.backgroundColor=temp;}-(void)didReceiveMemoryWarning{[superdidReceiveMemoryWarning];//Disposeofanyresourcesthatcanberecreated.}/*#pragmamark-Navigation//Inastoryboard-basedapplication,youwilloftenwanttodoalittlepreparationbeforenavigation-(void)prepareForSegue:(UIStoryboardSegue*)seguesender:(id)sender{//Getthenewviewcontrollerusing[seguedestinationViewController].//Passtheselectedobjecttothenewviewcontroller.}*/@end