UI programming of iOS--the realization of neon sign

Source: Internet
Author: User

Learning UI programming has been three or four days, and these days you have learned some of the primary views and controls, such as Uiview,uilabel and UIButton. To learn UI programming, it is a little fun to write your own code can see the effect. This differs greatly from the C language and OC. So I tried to do a simple view color transformation of the application, that is, neon. Functions can be implemented from the inside out, or from outside to inside, you can also pause. Because of the limited level, plus has not learned nstimer, just from the Internet to understand the simple application, so code implementation may have some problems, the algorithm is not optimal, but also hope that the great God criticized the guidance. Put a picture on it:


The following code implementation is attached:

#import "ZZAppDelegate.h" @interface zzappdelegate () {UIView *_containerview; Nstimer *_timer;} @end @implementation zzappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (    Nsdictionary *) launchoptions{Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];    Override point for customization after application launch.    Self.window.backgroundColor = [Uicolor Graycolor];    _containerview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, 320, 568)];    _containerview.backgroundcolor = [Uicolor Clearcolor];    [Self.window Addsubview:_containerview];    [_containerview release]; View layout Nsarray *array = [Nsarray arraywithobjects:[uicolor redcolor], [Uicolor Orangecolor], [Uicolor YellowColor], [U        Icolor Greencolor], [Uicolor Bluecolor], [Uicolor Cyancolor], [Uicolor Purplecolor], nil]; for (int i = 0; i < 7; i++) {UIView *view = [[UIView alloc] Initwithframe:cgrectmake (+ i *, + + i * 280-i *, 280-i * 40)];            View.backgroundcolor = Array[i];            View.tag = i + 200;            NSLog (@ "%ld", (long) view.tag);            [_containerview Addsubview:view];        [View release];    }//created from Inside Out button UIButton *button1 = [UIButton Buttonwithtype:uibuttontypesystem];    Button1.frame = CGRectMake (40, 450, 70, 40);    Button1.backgroundcolor = [Uicolor Cyancolor];    [Button1 settitle:@ "from the Inside Out" forstate:uicontrolstatenormal];    [Button1 addtarget:self Action: @selector (Changefromintoout) forcontrolevents:uicontroleventtouchupinside];    Button1.layer.cornerRadius = 7;    [_containerview Addsubview:button1];    Create Stop button UIButton *button2 = [UIButton Buttonwithtype:uibuttontypesystem];    Button2.frame = CGRectMake (125, 450, 70, 40);    Button2.backgroundcolor = [Uicolor Cyancolor];    [Button2 settitle:@ "Stop" forstate:uicontrolstatenormal]; [Button2 addtarget:self Action: @selector (STOP)Forcontrolevents:uicontroleventtouchupinside];    Button2.layer.cornerRadius = 7;    [_containerview Addsubview:button2];    Created by the outside of the inside button UIButton *button3 = [UIButton Buttonwithtype:uibuttontypesystem];    Button3.frame = CGRectMake (210, 450, 70, 40);    Button3.backgroundcolor = [Uicolor Cyancolor];    [Button3 settitle:@] from outside and inside "forstate:uicontrolstatenormal";    [Button3 addtarget:self Action: @selector (Changefromouttoin) forcontrolevents:uicontroleventtouchupinside];    Button3.layer.cornerRadius = 7;    [_containerview Addsubview:button3];    [Self.window makekeyandvisible]; return YES;} Trigger event from Inside Out button-(void) changefromintoout{_timer = [Nstimer scheduledtimerwithtimeinterval:0.3 target:self selector: @sel Ector (changeintoout) Userinfo:nil Repeats:yes];} Out-of-the-inside button out trigger event-(void) changefromouttoin{_timer = [Nstimer scheduledtimerwithtimeinterval:0.3 target:self selector: @se Lector (Changeouttoin) Userinfo:nil Repeats:yes];} Pause Timer-(void) stop{[_timer INvalidate];}    Swap colors from Inside Out-(void) changeintoout{UIView *temp = [[UIView alloc] init];    int i = 200;    Temp.backgroundcolor = [_containerview viewwithtag:200].backgroundcolor; for (i = $; i < 207; i++) {[_containerview viewwithtag:i].backgroundcolor = [_containerview viewwithtag:i +    1].backgroundcolor;    } [_containerview Viewwithtag:206].backgroundcolor =temp.backgroundcolor; [Temp release];}    The outer and inner loops swap colors-(void) changeouttoin{UIView *temp = [[UIView alloc] init];    int i = 206;    Temp.backgroundcolor = [_containerview viewwithtag:206].backgroundcolor; for (i = 206; I >= 0; i--) {[_containerview viewwithtag:i].backgroundcolor = [_containerview viewwithtag:i-1    ].backgroundcolor;    } [_containerview Viewwithtag:200].backgroundcolor =temp.backgroundcolor; [Temp release];}    -(void) dealloc{[_window release]; [Super Dealloc];} @end


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.