霓虹灯

#import "RootView.h"
#import "UIColor+RsndomColor.h"

@implementation RootView


- (instancetype)initWithFrame:(CGRect)frame
{
 
   self =[super initWithFrame:frame];
    if (self){
       [self addSubviews];
    }
    returnself;
}

#pragma mark - 创建view
- (UIView *)creatViewWithFrame:(CGRect)frame andColor:(UIColor*)color
{
    UIView *view= [[UIView alloc] initWithFrame:frame];
   view.backgroundColor = color;
   view.layer.cornerRadius = frame.size.height / 2;
    returnview;
}


- (void)addSubviews
{
   self.backgroundColor = [UIColor cyanColor];
    
    self.view1 =[self creatViewWithFrame:CGRectMake(20, 50, 300, 300)andColor:[UIColor redColor]];
    [selfaddSubview:self.view1];
    
    self.view2 =[self creatViewWithFrame:CGRectMake(40, 70, 260, 260)andColor:[UIColor yellowColor]];
    [selfaddSubview:self.view2];
    
    self.view3 =[self creatViewWithFrame:CGRectMake(60, 90, 220, 220)andColor:[UIColor greenColor]];
    [selfaddSubview:self.view3];
    
    self.view4 =[self creatViewWithFrame:CGRectMake(80, 110, 180, 180)andColor:[UIColor orangeColor]];
    [selfaddSubview:self.view4];
    
    self.view5 =[self creatViewWithFrame:CGRectMake(100, 130, 140, 140)andColor:[UIColor blueColor]];
    [selfaddSubview:self.view5];
    
//    for (int i= 0; i < 5; i++) {
//       self.view[i] = [self creatViewWithFrame:CGRectMake(20 + i * 20, 50+ i * 20, 300 - i * 40, 300 - i * 40) andColor:[UIColorrandomColor]];
//       [self addSubview:self.view[i]];
//    }
    
//    UIView*under = [self creatViewWithFrame:CGRectMake(0, 350, 375, 310)andColor:[UIColor cyanColor]];
    
    for (int i=0; i < 4; i++) {
       UIView *view = [[UIView alloc] initWithFrame:CGRectMake(170 , 350 +i * 72 , 10, 70)];
       view.backgroundColor = [UIColor randomColor];
       [self addSubview:view];
//       [under addSubview:view];
    }
    
//    [selfaddSubview:under];
//    [underrelease];

    
    //定时器
    [NSTimerscheduledTimerWithTimeInterval:.8 target:selfselector:@selector(changeColor) userInfo:nil repeats:YES];
    
    [NSTimerscheduledTimerWithTimeInterval:.8 target:selfselector:@selector(changeColorx) userInfo:nil repeats:YES];
    
}

- (void)changeColor
{
    UIColor*color = self.view5.backgroundColor;
   self.view5.backgroundColor = self.view4.backgroundColor;
   self.view4.backgroundColor = self.view3.backgroundColor;
   self.view3.backgroundColor = self.view2.backgroundColor;
   self.view2.backgroundColor = self.view1.backgroundColor;
   self.view1.backgroundColor = color;
//    NSUIntegercount = [self.subviews count] - 1;
//    for(NSUInteger i = 0; i < count - 1; i++) {
//       UIView v1 = ((UIView *)(self.subviews[count])).subviews[0];
//       UIView v2 = ((UIView *)(self.subviews[count])).subviews[1];
//    }
    
    
}

- (void)changeColorx
{
    UIColor*color = ((UIView *)self.subviews[5]).backgroundColor;
    ((UIView*)self.subviews[5]).backgroundColor = ((UIView*)self.subviews[6]).backgroundColor;
    ((UIView*)self.subviews[6]).backgroundColor = ((UIView*)self.subviews[7]).backgroundColor;
    ((UIView*)self.subviews[7]).backgroundColor = ((UIView*)self.subviews[8]).backgroundColor;
    ((UIView*)self.subviews[8]).backgroundColor = color;

}

- (void)dealloc
{
    [_view1release];
    [_view2release];
    [_view3release];
    [_view4release];
    [_view5release];
    [superdealloc];
}



@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值