IOS Neon Effect

Source: Internet
Author: User

The general idea is as follows:

Using the For loop to create n view, and add them to the variable array, using Nstimer, to achieve the effect of cyclic discoloration (ChangeColor:), the idea of color change: The background color of the I-View and i + 1 view background color Exchange, a round can be changed, ( Nstimer will automatically implement loops)

This is in the attempt to write the controller, so the view is added to Self.view, Self.view.subviews (is an array (inside the individual view))

-(void) Viewdidload {
[Super Viewdidload];

for (int i = 0; i < 6; i++) {
UIView * view = [[UIView alloc] Initwithframe:cgrectmake (i *, I *, self.view.frame.size.width-i *, self.view.fr Ame.size.height-i * 80)];//CREATE view
View.backgroundcolor = [Uicolor colorwithred:arc4random ()% 256/255.0 green:arc4random ()% 256/255.0 blue:arc4random ( )% 256/255.0 alpha:1];//background color random assignment
[Self.view addsubview:view];//add it to (array)
[View release];
}

Nstimer * timer = [Nstimer scheduledtimerwithtimeinterval:.8 target:self selector: @selector (changecolor:) UserInfo: Self.view.subviews repeats:yes];//has been circulating (self.view.subviews to (ChangeColor:))
[Timer fire];

-(void) ChangeColor: (Nstimer *) sender
{
Nsmutablearray * ary = [Nsmutablearray arrayWithArray:sender.userInfo];
UIView * v = [[UIView alloc] init];
for (int i = 0; i < ary.count-1; i++) {//swap the background color of the I view with the background color of the i + 1 view
UIView * V1 = [ary objectatindex:i];
UIView * v2 = [ary objectatindex:i + 1];
V.backgroundcolor = V1.backgroundcolor;
V1.backgroundcolor = V2.backgroundcolor;
V2.backgroundcolor = V.backgroundcolor;
}
}

IOS Neon Effect

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.