利用UIView做出霓虹燈的效果,uiview做出霓虹燈

來源:互聯網
上載者:User

利用UIView做出霓虹燈的效果,uiview做出霓虹燈

效果


代碼如下(只有實現部分)

@interface AppDelegate ()@end@implementation AppDelegate- (void)dealloc{    [_window release];    [super dealloc];}- (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 whiteColor];    [self.window makeKeyAndVisible];    [_window release];        // 定義view,顏色模組    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 340, 340)];    view1.backgroundColor = [UIColor greenColor];    [self.window addSubview:view1];    [view1 release];    view1.tag = 1;        UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(40, 40, 300, 300)];    view2.backgroundColor = [UIColor purpleColor];    [self.window addSubview:view2];    [view2 release];    view2.tag = 2;        UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(60, 60, 260, 260)];    view3.backgroundColor = [UIColor magentaColor];    [self.window addSubview:view3];    [view3 release];    view3.tag = 3;        UIView *view4 = [[UIView alloc] initWithFrame:CGRectMake(80, 80, 220, 220)];    view4.backgroundColor = [UIColor redColor];    [self.window addSubview:view4];    [view4 release];    view4.tag = 4;        UIView *view5 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 180, 180)];    view5.backgroundColor = [UIColor orangeColor];    [self.window addSubview:view5];    [view5 release];    view5.tag = 5;        UIView *view6 = [[UIView alloc] initWithFrame:CGRectMake(120, 120, 140, 140)];    view6.backgroundColor = [UIColor yellowColor];    [self.window addSubview:view6];    [view6 release];    view6.tag = 6;        UIView *view7 = [[UIView alloc] initWithFrame:CGRectMake(140, 140, 100, 100)];    view7.backgroundColor = [UIColor cyanColor];    [self.window addSubview:view7];    [view7 release];    view7.tag = 7;    // 定義一個timer,實現色塊變化     NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(changeColor) userInfo:nil repeats:YES];        return YES;}- (void)changeColor{    // 定義一個color來接收7的顏色    UIColor *color = [self.window viewWithTag:7].backgroundColor;    // 換顏色    for (int i = 6 ; i > 0; i--) {        [self.window viewWithTag:i + 1].backgroundColor = [self.window viewWithTag:i ].backgroundColor;    }    // 最裡面給最外面    [self.window viewWithTag:1].backgroundColor = color;}@end


著作權聲明:本文為博主原創文章,轉載請註明原文地址

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.