In the rootviewcontroller.m file
-(void) viewdidload//View Load method
- (void) viewdidload{//Set RedUIView *viewred = [[UIView alloc]initwithframe:cgrectmake ( -, -, -, -)]; Viewred.backgroundcolor=[Uicolor Redcolor]; [Self.view addsubview:viewred]; //Set OrangeUIView *vieworange = [[UIView alloc]initwithframe:cgrectmake ( -, the, -, -)]; Vieworange.backgroundcolor=[Uicolor Orangecolor]; [Self.view Addsubview:vieworange]; //Set YellowUIView*viewyellow = [[UIView alloc]initwithframe:cgrectmake ( -, the, -, -)]; Viewyellow.backgroundcolor=[Uicolor Yellowcolor]; [Self.view Addsubview:viewyellow]; //Set GreenUIView *viewgreen = [[UIView alloc]initwithframe:cgrectmake ( -, the, -, -)]; Viewgreen.backgroundcolor=[Uicolor Greencolor]; [Self.view Addsubview:viewgreen]; //Set CyanUIView *viewgray = [[UIView alloc]initwithframe:cgrectmake ( -, -, -, -)]; Viewgray.backgroundcolor=[Uicolor Graycolor]; [Self.view Addsubview:viewgray]; //Set BlueUIView *viewblue = [[UIView alloc]initwithframe:cgrectmake ( -, -, -, -)]; Viewblue.backgroundcolor=[Uicolor Bluecolor]; [Self.view Addsubview:viewblue]; //Set PurpleUIView *viewpurple = [[UIView alloc]initwithframe:cgrectmake ( -,280, -, -)]; Viewpurple.backgroundcolor=[Uicolor Purplecolor]; [Self.view Addsubview:viewpurple]; //Set ButtonUIButton *button =[UIButton Buttonwithtype:uibuttontyperoundedrect]; Button.frame= CGRectMake ( -, the, -, -); [Button Settitle:@"Start"Forstate:uicontrolstatenormal]; Button.backgroundcolor=[Uicolor Blackcolor]; Button.tag=108; [Button addtarget:self action: @selector (btnaction:) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button]; [Super Viewdidload]; //Do any additional setup after loading the view.}
In the Association method btnaction:
Timer is a global variable
Can be defined in the RootViewController.h file;
-(void) Btnaction: (ID) sender{ *button = (uibutton*) sender; if (Button.tag = =108) {= [Nstimer scheduledtimerwithtimeinterval:1 target:self Selector: @selector (dochangecolor:) Userinfo:nil Repeats:yes]; [Timer fire]; // Timer Start } }
In the Association method Dochangecolor:
-(void) Dochangecolor: (ID) sender{Nsarray*arr = Self.view.subviews;//get all the views intCount = [Arr count]-1;//Get CountUIView *firstview = [arr objectatindex:0]; Uicolor*firstcolor =Firstview.backgroundcolor; for(intI=0; i<count; i++) {UIView*view =[arr objectatindex:i]; UIView*nextview = [arr objectatindex: (i+1)]; View.backgroundcolor=Nextview.backgroundcolor; } ((UIView*) [arr Objectatindex:count]). BackgroundColor =Firstcolor; Self.view.backgroundColor= [Uicolor colorwithred: (arc4random ()%255/255.0) Green: (Arc4random ()%255/255.0) Blue: (Arc4random ()%255/255.0) Alpha: (Arc4random ()%255/255.0)]; }
The results show:
Will constantly change the background image, and achieve the effect of neon.