IOS Neon Simple Applet

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.