码迷,mamicode.com
首页 > 其他好文 > 详细

七彩霓虹灯可以实现两种效果

时间:2014-08-23 14:02:02      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   for   ar   2014   art   

bubuko.com,布布扣

//  MHTAppDelegate.h

//  HomeworkNeonLamp

//  Copyright (c) 2014 Summer. All rights reserved.


#import <UIKit/UIKit.h>

@interface MHTAppDelegate : UIResponder <UIApplicationDelegate>

@property (retain, nonatomic) UIWindow *window;

@end




//  MHTAppDelegate.m

//  HomeworkNeonLamp

//  Copyright (c) 2014 Summer. All rights reserved.

#import "MHTAppDelegate.h"

@interface MHTAppDelegate()

{

    UIView *_containerView;

    UIView *_toOutsideView;

    UIView *_toInsideView;

    UIView *_otherView;

    UIView *_view;

    NSArray *_color;

}

@end

@implementation MHTAppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

     _color = [NSArray arrayWithObjects:[UIColor redColor], [UIColor orangeColor], [UIColor yellowColor], [UIColor greenColor], [UIColor blueColor], [UIColor cyanColor], [UIColor purpleColor], nil];

    //创建背景画布

    _containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

    _containerView.backgroundColor = [UIColor clearColor];

    [self.window addSubview:_containerView];

    [_containerView release];

    

    _toOutsideView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

    _toOutsideView.backgroundColor = [UIColor clearColor];

    [_containerView addSubview:_toOutsideView];

    _toOutsideView.tag = 100;

    [_toOutsideView release];

    

    _toInsideView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];

    _toInsideView.backgroundColor = [UIColor clearColor];

    [_containerView addSubview:_toInsideView];

    _toInsideView.tag = 101;

    [_toInsideView release];

    

    [self toIN];

    [self toOUT];

    [self but];

    [self Line];

     [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(click) userInfo:nil repeats:YES];

     self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}

- (void)toIN

{

    for (int i = 0; i < 7; i++) {

        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10 + 20 * i, 80 + 34 + 30 * i, 300 - (0 + 20 * i) * 2, 500 - (80 + 30 * i) * 2)];

        view.backgroundColor = [_color objectAtIndex:i];

        [_toInsideView addSubview:view];

        [view release];

        view.tag = 200 + i;

    }

    NSLog(@"%@", [_toInsideView subviews]);

}


- (void)toOUT

{

    for (int i = 0; i < 7; i++) {

        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10 + 20 * i, 80 + 34 + 30 * i, 300 - (0 + 20 * i) * 2, 500 - (80 + 30 * i) * 2)];

        view.backgroundColor = [_color objectAtIndex:i];

        [_toOutsideView addSubview:view];

        [view release];

        view.tag = 200 + i;

    }

    NSLog(@"%@", [_toOutsideView subviews]);

}

- (void)but

{

    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];

    but.frame = CGRectMake(10, 30, 300, 30);

    [but setTitle:@"      " forState:UIControlStateNormal];

    but.titleLabel.font = [UIFont fontWithName:@"EuphemiaUCAS" size:20 ];

    [but setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    but.backgroundColor = [UIColor yellowColor];

    but.layer.cornerRadius = 5;

    but.layer.borderWidth = 1;

    but.layer.borderColor = [[UIColor blueColor] CGColor];

    [but addTarget:self action:@selector(butClick:) forControlEvents:UIControlEventTouchUpInside];

    [_containerView addSubview:but];

    but.tag = 104;

}

- (void)butClick:(UIButton *)but

{

    [_containerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

}

- (void)click

{

    //由里向外

    UIView *temp = [[UIView alloc] init];

    temp.backgroundColor = [_toOutsideView viewWithTag:200].backgroundColor;

    for (int i = 200; i < 206; i++) {

        [_toOutsideView viewWithTag:i].backgroundColor = [_toOutsideView viewWithTag: i + 1].backgroundColor;

    }

    [_toOutsideView viewWithTag:206].backgroundColor =temp.backgroundColor;

    [temp release];

    //由外向里

    UIView *temp1 = [[UIView alloc] init];

    temp1.backgroundColor = [_toInsideView viewWithTag:206].backgroundColor;

    for (int i = 206; i > 200; i--) {

        [_toInsideView viewWithTag:i].backgroundColor = [_toInsideView viewWithTag:i - 1].backgroundColor;

    }

    [_toInsideView viewWithTag:200].backgroundColor = temp1.backgroundColor;

    [temp1 release];

    

}

- (void)Line

{

    //copyrightLine(版权)

    UILabel *copyrightLine = [[UILabel alloc] initWithFrame:CGRectMake(20, 520, 280, 2)];

    copyrightLine.backgroundColor = [UIColor grayColor];

    copyrightLine.layer.cornerRadius = 5;

    copyrightLine.layer.masksToBounds = YES;

    [_containerView addSubview:copyrightLine];

    [copyrightLine release];

    UILabel *copyrightLable = [[UILabel alloc] initWithFrame:CGRectMake(20, 480, 280, 20)];

    copyrightLable.textAlignment = NSTextAlignmentCenter;

    copyrightLable.text = @"Copyright ? 2014 summer";

    copyrightLable.font = [UIFont fontWithName:@"AppleSDGothicNeo-Thin" size:12];

    [_containerView addSubview:copyrightLable];

    [copyrightLable release];

    UILabel *copyrightLable1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 500, 280, 20)];

    copyrightLable1.textAlignment = NSTextAlignmentCenter;

    copyrightLable1.text = @"summer2014mht@sina.com";

    copyrightLable1.font = [UIFont fontWithName:@"AppleSDGothicNeo-Thin" size:12];

    [_containerView addSubview:copyrightLable1];

    [copyrightLable1 release];


}

- (void)applicationWillResignActive:(UIApplication *)application

{

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


- (void)applicationDidEnterBackground:(UIApplication *)application

{

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application

{

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application

{

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application

{

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

- (void)dealloc

{

    [_window release];

    [super dealloc];

}

@end

七彩霓虹灯可以实现两种效果

标签:style   blog   http   color   io   for   ar   2014   art   

原文地址:http://blog.csdn.net/mhtios/article/details/38777887

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!