**************************NO.1**********************
{
UIView *view1;
UIView *view2;
UIView *view3;
UIView *view4;
UIView *view5;
UIView *view6;
UIView *view7;
UIColor *red;
UIColor *white;
UIColor *green;
UIColor *magenta;
UIColor *orange;
UIColor *brown;
UIColor *blue;
}
@end
@implementationAppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
ViewController *lamp = [[ViewController alloc]init];
self.window.backgroundColor = [UIColor blackColor];
self.window.rootViewController = lamp;
view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
[self.window addSubview:view1];
view2 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[view1 addSubview:view2];
view3 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[view2 addSubview:view3];
view4 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[view3 addSubview:view4];
view5 = [[UIView alloc]initWithFrame:CGRectMake(0, 101, 100, 100)];
[view4 addSubview:view5];
view6 = [[UIView alloc]initWithFrame:CGRectMake(-101, 0, 100, 100)];
[view5 addSubview:view6];
view7 = [[UIView alloc]initWithFrame:CGRectMake(-202, 0, 100, 100)];
[view5 addSubview:view7];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(sture) userInfo:nil repeats:YES];
red = [UIColor redColor];
white = [UIColorwhiteColor];
green = [UIColorgreenColor];
magenta = [UIColor magentaColor];
orange = [UIColororangeColor];
brown = [UIColorbrownColor];
blue = [UIColorblueColor];
return YES;
}
-(void)sture{
// if (view1.hidden == YES) {
// view2.hidden = NO;
// }
// else{
//
// view2.hidden = YES;
// }
NSArray *list = @[view1,view2,view3,view4,view5,view6,view7];
NSArray *List = @[red, white,green,magenta,orange,brown,blue];
for (int i=0; i<list.count;i++) {
UIView *a = list[i];
UIColor *b = List[arc4random()%7];
a.backgroundColor = b;
a.alpha = 1;
}
}
{
int b;
NSArray *list;
UIView *_cmm;
UIView *_cmm1;
UIView *_cmm2;
UIView *_cmm3;
}
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
ViewController *vc = [[ViewController alloc]init];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
_cmm = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 80, 80)];
_cmm1 = [[UIView alloc]initWithFrame:CGRectMake(110, 30, 80, 80)];
_cmm2 = [[UIView alloc]initWithFrame:CGRectMake(30, 110, 80, 80)];
_cmm3 = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 80, 80)];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(start) userInfo:nil repeats:YES];
return YES;
}
- (void)start
{list = @[[UIColor yellowColor],[UIColor cyanColor],[UIColor greenColor],[UIColor blueColor],[UIColor redColor],[UIColor brownColor],[UIColor purpleColor]];
int c = arc4random()%list.count;
int d = arc4random()%list.count;
int e = arc4random()%list.count;
int f = arc4random()%list.count;
switch (b) {
case 1:
[self.window addSubview:_cmm];
_cmm.backgroundColor = list[c];
break;
case 2:
[self.window addSubview:_cmm1];
_cmm1.backgroundColor = list[d];
break;
case 3:
[self.window addSubview:_cmm3];
_cmm3.backgroundColor = list[e];
break;
case 4:
[self.window addSubview:_cmm2];
_cmm2.backgroundColor = list[f];
break;
case 5:
[_cmm2 removeFromSuperview];
break;
case 6:
[_cmm3 removeFromSuperview];
break;
case 7:
[_cmm1 removeFromSuperview];
break;
case 8:
[_cmm removeFromSuperview];
break;
}
b++;
if (b==9) {
b=1;
}
}
**************************************NO.3**************************************/颜色数组
NSArray *array = [NSArrayarrayWithObjects:[UIColor redColor], [UIColor orangeColor], [UIColoryellowColor], [UIColor greenColor], [UIColor blueColor], [UIColor cyanColor],[UIColor purpleColor], nil];
// int r = arc4random()%array.count;
//循环生成视图
for (int i = 0; i<7; i++)
{
UIView *view =[[UIViewalloc]initWithFrame:CGRectMake(30, 100, 180-i*30, 250)];
view.backgroundColor = array[i];
view.tag = 99+i;
[self.window addSubview:view];
// view=view3;
}
// //在同一个父视图中
1.view1 移动到最上面
// [self.window bringSubviewToFront:view1];
// 把一个视图移动到底下
// [self.window sendSubviewToBack:view2];
// 交换两个视图的位置
// -(void)exchangeSubviewAtIndex:(NSInteger)index1withSubviewAtIndex:(NSInteger)index2;
// 通过下标
// [self.window exchangeSubviewAtIndex:2withSubviewAtIndex:1];
// subviews(所有的子视图组成的数组) 数组->
// self.window.subviews;
// 初始化视图的顺序 就是把视图存放到subviews 这个数组里面的顺序
// 改变视图的顺序 就是在改变 subviews数组里面元素的位置
// NSLog(@"%@",self.window.subviews);
// UIView *view = self.window.subviews[0];
// NSLog(@"%@",view);
// 插入视图 above到XX的上面
UIView *insertView = [[UIViewalloc]initWithFrame:CGRectMake(80, 250, 80, 80)];
insertView.backgroundColor = [UIColorgrayColor];
[self.window insertSubview:insertViewaboveSubview:view1];
// [self.window insertSubview:<#(nonnullUIView *)#> atIndex:<#(NSInteger)#>
// [self.window insertSubview:<#(nonnullUIView *)#> belowSubview:<#(nonnull UIView *)#>
// tag 标记 标签 标号->同一个父视图里面的身份证号
insertView.tag = 100;
// 可以通过tag值 在他的父视图上找到 这视图
// viewWithTag:在一个父视图上面查找有没有tag值是多少的视图
UIView *v=[self.window viewWithTag:100];
// V就是insertView了
****************************************NO.4*****************************************
-(BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window makeKeyAndVisible];
//定义颜色数组
NSMutableArray *arr = [NSMutableArrayarrayWithObjects:[UIColor redColor], [UIColor yellowColor],[UIColorblueColor],[UIColor greenColor],[UIColor grayColor],[UIColorpurpleColor],[UIColor orangeColor],nil];
//for循环 设定位置 颜色
for (int i = 0 ; i < 7; i++) {
UIView *view =[[UIView alloc] initWithFrame:CGRectMake(i * 20, i *20, 320 - 40 * i , 568 - i * 40)];//x y轴依次改变,宽高依次减小 xy越大 宽高越小
view.tag = 100 + i;//设置tag
view.backgroundColor =arr[i];//设置视图颜色(从可变数组arr中读取)
[self.window addSubview:view];//添加到主窗口
}
[NSTimerscheduledTimerWithTimeInterval:0.01 target:self selector:@selector(time)userInfo:nil repeats:YES];
self.window.backgroundColor = [UIColorwhiteColor];
return YES;
}
- (void)time
{
UIColor *te = [self.windowviewWithTag:100 ].backgroundColor;//查找tag为100的视图,操作te就是操作tag为100的视图,这里设置te是为了实现递进,先保存tag=100的视图的颜色,左后重新赋值给最后一个视图
for (int i = 0; i <6; i++) {
[self.window viewWithTag:100 +i].backgroundColor = [self.windowviewWithTag:101 +i ].backgroundColor;
}
[self.window viewWithTag:106].backgroundColor = te;
}
**************************************************NO.5***********************************************************- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
x = 0;
y = 1;
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds] ;
ViewController *vc = [[ViewController alloc]init];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
self.window.backgroundColor = [UIColor whiteColor];
colorList = [[NSMutableArray alloc]initWithObjects:[UIColor yellowColor],[UIColor greenColor],[UIColor grayColor],[UIColor purpleColor],[UIColor redColor],[UIColor blackColor],[UIColor brownColor], nil];
list = [NSMutableArray array];
for (int i = 0; i <3;i++) {
for (intj =0 ; j<3;j++) {
view = [[UIView alloc]init];
view.frame = CGRectMake(i* 100 +100,j*100+100,80, 80);
view.backgroundColor = colorList[j];
[list addObject:view];
view.tag = x + 1;
x++;
[self.window addSubview:view];
}
}
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(start) userInfo:nil repeats:YES];
return YES;
}
- (void)start{
x = 0 ;
for (int i = 0; i<9; i++){
int r = arc4random()%colorList.count;
[self.windowviewWithTag:x+ 1].backgroundColor= colorList[r];
x++;
}
switch (y) {
case 1:
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
case 2:
[self.window viewWithTag:y-1].alpha = 1 ;
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
case 3:
[self.window viewWithTag:y-1].alpha = 1 ;
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
case 4:
[self.window viewWithTag:y-1].alpha = 1 ;
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
case 5:
[self.window viewWithTag:y-1].alpha = 1 ;
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
case 6:
[self.window viewWithTag:y-1].alpha = 1 ;
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
case 7:
[self.window viewWithTag:y-1].alpha = 1 ;
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
case 8:
[self.window viewWithTag:y-1].alpha = 1 ;
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
case 9:
[self.window viewWithTag:y-1].alpha = 1 ;
[self.window viewWithTag:y].alpha = 0 ;
y++;
break;
default:
[self.window viewWithTag:y-1].alpha = 1 ;
y=1;
break;
}
}