基于Objective-C的iOS霓虹灯程序

2 篇文章 0 订阅
2 篇文章 0 订阅

霓虹灯

基于OC实现的霓虹灯效果,看着有点刺眼。。。不过很好玩。
效果图:
这里写图片描述
你需要做的东西,就是用Xcode新建一个iOS工程,然后将下面代码敲上就可以实现。
代码如下:

UIView *yellow = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 600)];
    yellow.backgroundColor = [UIColor yellowColor];
    yellow.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2);
    yellow.tag = 1;
    [self.window addSubview:yellow];
    [yellow release];

    UIView *red = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)];
    red.backgroundColor = [UIColor redColor];
    red.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2);
    red.tag = 2;
    [self.window addSubview:red];
    [red release];

    UIView *blue = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 225, 400)];
    blue.backgroundColor = [UIColor blueColor];
    blue.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2);
    blue.tag = 3;
    [self.window addSubview:blue];
    [blue release];

    UIView *green = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 300)];
    green.backgroundColor = [UIColor greenColor];
    green.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2);
    green.tag = 4;
    [self.window addSubview:green];
    [green release];

    UIView *gray = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 75, 200)];
    gray.backgroundColor = [UIColor grayColor];
    gray.center = CGPointMake((self.window.frame.size.width) / 2, (self.window.frame.size.height) / 2);
    gray.tag = 5;
    [self.window addSubview:gray];
    [gray release];



    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(change) userInfo:nil repeats:YES];

下面是一个方法:

- (void)change
{
    UIView *yellow = [self.window viewWithTag:1];

    UIView *red = [self.window viewWithTag:2];

    UIView *blue = [self.window viewWithTag:3];

    UIView *green = [self.window viewWithTag:4];

    UIView *gray = [self.window viewWithTag:5];

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

    temp.backgroundColor = yellow.backgroundColor;
    yellow.backgroundColor = red.backgroundColor;
    red.backgroundColor = blue.backgroundColor;
    blue.backgroundColor = green.backgroundColor;
    green.backgroundColor = gray.backgroundColor;
    gray.backgroundColor = temp.backgroundColor;
}

应该就是这些了,基本的小东西,挺好玩的。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值