#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];
//定时器
[NSTimerscheduledTimerWithTimeIn terval:.8 target:selfselector:@selector(changeColor) userInfo:nil repeats:YES];
[NSTimerscheduledTimerWithTimeIn terval:.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
#import "UIColor+RsndomColor.h"
@implementation RootView
- (instancetype)initWithFrame:(CGRect)frame
{
}
#pragma mark - 创建view
- (UIView *)creatViewWithFrame:(CGRect)frame andColor:(UIColor*)color
{
}
- (void)addSubviews
{
//
//
//
//
//
//
//
//
}
- (void)changeColor
{
//
//
//
//
//
}
- (void)changeColorx
{
}
- (void)dealloc
{
}
@end