霓虹灯效果(UIView)

- (void)viewDidLoad

{

    [superviewDidLoad];

    self.view.backgroundColor = [UIColorgrayColor];  

  

    UIView *view1 = [[UIViewallocinitWithFrame:CGRectMake(2020280320)];

    view1.tag = 100;

    view1.backgroundColor = [UIColorredColor];

    [self.viewaddSubview:view1];

    [view1 release];

    

    UIView *view2 = [[UIViewallocinitWithFrame:CGRectMake(2020240280)];

    view2.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

    view2.tag = 101;

    view2.backgroundColor = [UIColorgreenColor];

    [view1 addSubview:view2];

    [view2 release];

    

    UIView *view3 = [[UIViewallocinitWithFrame:CGRectMake(2020200240)];

    // view3.alpha = 0.2;

    view3.tag = 102;

    view3.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;

    view3.backgroundColor = [UIColorblackColor];

    [view2 addSubview:view3];

    [view3 release];


    UIButton *zoomOutBtn = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [zoomOutBtn setTitle:@"放大"forState:UIControlStateNormal];

    zoomOutBtn.frame = CGRectMake(2035010050);

    [zoomOutBtn addTarget:self action:@selector(zoomOut) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:zoomOutBtn];

    

    UIButton *zoomInBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [zoomInBtn setTitle:@"缩小"forState:UIControlStateNormal];

    zoomInBtn.frame = CGRectMake(20035010050);

    [zoomInBtn addTarget:selfaction:@selector(zoomIn) forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:zoomInBtn];


 

    colorArray = [[NSArrayallocinitWithObjects:[UIColorredColor],[UIColororangeColor],         [UIColoryellowColor],[UIColorgreenColor],[UIColorblackColor],[UIColorblueColor],[UIColorpurpleColor], nil];

    

    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(changeColor) userInfo:nilrepeats:YES];

}


- (void)changeColor

{

    /*

    UIView *view1 = [self.view viewWithTag:100];

    UIView *view2 = [self.view viewWithTag:101];

    UIView *view3 = [self.view viewWithTag:102];

    

    UIColor *temp = view1.backgroundColor;

    view1.backgroundColor = view2.backgroundColor;

    view2.backgroundColor = view3.backgroundColor;

    view3.backgroundColor = temp;

    */

 

    staticint i = 0;

    staticint j = 1;

    staticint k = 2;

    

    UIView *view1 = [self.viewviewWithTag:100];

    view1.backgroundColor = [colorArray objectAtIndex:i];

    UIView *view2 = [self.viewviewWithTag:101];

    view2.backgroundColor = [colorArray objectAtIndex:j];

    UIView *view3 = [self.viewviewWithTag:102];

    view3.backgroundColor = [colorArray objectAtIndex:k];

    

    if (i++ == 6) {

        i = 0;

    }

    if (j++ == 6) {

        j = 0;

    }

    if (k++ == 6) {

        k = 0;

    }

}


- (void)zoomOut

{

    UIView *view1 = [self.viewviewWithTag:100];

    [view1 setFrame:CGRectInset(view1.frame, -10, -10)];

}


- (void)zoomIn

{

    UIView *view1 = [self.viewviewWithTag:100];

    [view1 setFrame:CGRectInset(view1.frame, 10, 10)];

}


//注意CGRectInset

/*

CGRect CGRectInset (
   CGRect rect,
   CGFloat dx,
   CGFloat dy
);
该结构体的应用是以原rect为中心,再参考dx,dy,进行缩放或者放大。
*/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值