Production of neon lights (forward, reverse, and stop)
// Create a neon view NSArray * arr = [NSArray arrayWithObjects: [UIColor purpleColor], [UIColor cyanColor], [UIColor blueColor], [UIColor greenColor], [UIColor yellowColor], [UIColor orangeColor], [UIColor redColor], nil]; for (int I = 0; I <7; I ++) {UIView * view = [[UIView alloc] initWithFrame: CGRectMake (20 + I * 20,120 + I * 20,280-I * 20*2,280-I * 20*2)]; view. backgroundColor = arr [I]; view. tag = 100 + I; [_ containerView addSubview: view]; [view release];}
// Create a button to control the neon light to stop UIButton * bun = [UIButton buttonWithType: UIButtonTypeSystem]; bun. frame = CGRectMake (50,420,220, 40); bun. layer. cornerRadius = 5; [bun setTitle: @ "stop" forState: UIControlStateNormal]; [bun addTarget: self action: @ selector (bun :) forControlEvents: UIControlEventTouchUpInside]; [_ containerView addSubview: bun];
// Create a button for the neon to run in reverse direction UIButton * stop = [UIButton buttonWithType: UIButtonTypeSystem]; stop. frame = CGRectMake (50,480,220, 40); stop. layer. cornerRadius = 5; [stop setTitle: @ "reverse" forState: UIControlStateNormal]; [stop addTarget: self action: @ selector (click) forControlEvents: UIControlEventTouchUpInside]; [_ containerView addSubview: stop];
// Set the interval _ time = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @ selector (test) userInfo: nil repeats: YES];
// Stop event-(void) bun :( UIButton *) btn {[_ time invalidate];}
// Click the event (void) test {UIView * view = [[UIView alloc] init]; view. backgroundColor = [_ containerView viewWithTag: 100]. backgroundColor; for (int I = 100; I <107; I ++) {[_ containerView viewWithTag: I]. backgroundColor = [_ containerView viewWithTag: I + 1]. backgroundColor;} [_ containerView viewWithTag: 106]. backgroundColor = view. backgroundColor; [view release];}
// Run the click Event reversely-(void) click {_ time = [nst1_scheduledtimerwithtimeinterval: 0.3 target: self selector: @ selector (clicks) userInfo: nil repeats: YES];} -(void) clicks {UIView * view = [[UIView alloc] init]; view. backgroundColor = [_ containerView viewWithTag: 106]. backgroundColor; for (int I = 106; I> 99; I --) {[_ containerView viewWithTag: I]. backgroundColor = [_ containerView viewWithTag: I-1]. backgroundColor;} [_ containerView viewWithTag: 100]. backgroundColor = view. backgroundColor; [view release];}
Through the above steps, we have basically completed a neon lamp production that can be forward, reverse, and stopped.
File: // Users/lanouhn/Desktop/1.gif