I had a friend who taught me iOS and asked me to help him write a neon code, and he didn't want to move his cancer. So there is the following thing ...
Define a macro first, space is the space between each view.
#define Space 10
Then, just need ... Okay, done, go to bed.
Feel like this to be killed, I still simply say the neon principle: the color of the Exchange view, and then the innermost view of the color of the outermost view, the loop is OK. Of course, in order to be lazy, I write directly in the APPDELEGATE.M, beg not to fight.
UIView *superview =Self.window; CGFloat width=[UIScreen mainscreen].bounds.size.width; CGFloat height=[UIScreen mainscreen].bounds.size.height; while(YES) {if(Width-2* Space) >0&& (Height-2* Space) >0) { //if the condition is true, the view is created all the time.UIView *subview = [[UIView Alloc]initwithframe:cgrectmake (Space, space, width-2* Space, Width-2*Space)]; Subview.backgroundcolor= [Uicolor colorwithred:arc4random ()% the/255.0Green:arc4random ()% the/255.0Blue:arc4random ()% the/255.0Alpha1];//Get random colors[Superview Addsubview:subview]; Superview=SubView; Width= width-2*Space; Height= Height-2*Space; [SubView release]; }Else { Break; }} [Nstimer Scheduledtimerwithtimeinterval:1Target:self selector: @selector (Exchangecolor) Userinfo:nil Repeats:yes];
Oh, yes, I almost forgot to write a way to swap colors ...
- (void) Exchangecolor {UIView*subview =Self.window.subviews.firstObject; Uicolor*tempcolor =Subview.backgroundcolor; while(YES) {if(subView.subviews.firstObject) {UIView*tempview =SubView.subviews.firstObject; Uicolor*TEMPC =Tempview.backgroundcolor; Tempview.backgroundcolor=Tempcolor; SubView=Tempview; Tempcolor=TEMPC; }Else{UIView*view =Self.window.subviews.firstObject; View.backgroundcolor=Subview.backgroundcolor; Break; } } }
The simplest one is as follows:
Then I was beaten by a friend.
Simple to die neon.