<pre name="code" class="objc">.h文件中的部分
@property (nonatomic, retain) NSTimer *time;
@property (nonatomic, retain) NSArray *array;
@property (nonatomic, retain) UIView *view1;
@property (nonatomic, retain) UIView *view2;
@property (nonatomic, retain) UIView *view3;
@property (nonatomic, retain) UIView *view4;
@property (nonatomic, retain) UIView *view5;
@property (nonatomic, retain) UIView *view6;
@property (nonatomic, retain) UIView *view7;
@property (nonatomic, retain) UIView *view8;
@property (nonatomic, retain) UIView *view9;
@property (nonatomic, retain) UIView *view10;
@property (nonatomic, retain) UIView *view11;
这是.m文件中的
self.array = [[NSArray alloc]initWithObjects:[UIColor yellowColor], [UIColor blackColor], [UIColor grayColor], [UIColor redColor], [UIColor blueColor], [UIColor brownColor], [UIColor greenColor], [UIColor magentaColor], [UIColor purpleColor], [UIColor whiteColor], [UIColor cyanColor], nil];
self.time = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(colorrun) userInfo:nil repeats:YES];
}
return self;
}
self.view1 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 400)];
[self.view1 setBackgroundColor:self.array[0]];
[self.view addSubview:self.view1];
self.view2 = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 280, 380)];
[self.view2 setBackgroundColor:self.array[1]];
[self.view addSubview:self.view2];
self.view3 = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 260, 360)];
[self.view3 setBackgroundColor:self.array[2]];
[self.view addSubview:self.view3];
self.view4 = [[UIView alloc]initWithFrame:CGRectMake(40, 40, 240, 340)];
[self.view4 setBackgroundColor:self.array[3]];
[self.view addSubview:self.view4];
self.view5 = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 220, 320)];
[self.view5 setBackgroundColor:self.array[4]];
[self.view addSubview:self.view5];
self.view6 = [[UIView alloc]initWithFrame:CGRectMake(60, 60, 200, 300)];
[self.view6 setBackgroundColor:self.array[5]];
[self.view addSubview:self.view6];
self.view7 = [[UIView alloc]initWithFrame:CGRectMake(70, 70, 180, 280)];
[self.view7 setBackgroundColor:self.array[6]];
[self.view addSubview:self.view7];
self.view8 = [[UIView alloc]initWithFrame:CGRectMake(80, 80, 160, 260)];
[self.view8 setBackgroundColor:self.array[7]];
[self.view addSubview:self.view8];
self.view9 = [[UIView alloc]initWithFrame:CGRectMake(90, 90, 140, 240)];
[self.view9 setBackgroundColor:self.array[8]];
[self.view addSubview:self.view9];
self.view10 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 120, 220)];
[self.view setBackgroundColor:self.array[9]];
self.view11 = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 100, 200)];
[self.view11 setBackgroundColor:self.array[10]];
[self.view addSubview:self.view11];
}
- (void)colorrun;
{
//NSLog(@"%d", i % 11);
self.view1.backgroundColor = self.array[i ++ % 11];
//NSLog(@"%d", i % 11);
self.view2.backgroundColor = self.array[i ++ % 11];
//NSLog(@"%d", i % 11);
self.view3.backgroundColor = self.array[i ++ % 11];
//NSLog(@"%d", i % 11);
self.view4.backgroundColor = self.array[i ++ % 11];
//NSLog(@"%d", i % 11);
self.view5.backgroundColor = self.array[i ++ % 11];
//NSLog(@"%d", i % 11);
self.view6.backgroundColor = self.array[i ++ % 11];
// NSLog(@"%d", i % 11);
self.view6.backgroundColor = self.array[i ++ % 11];
//NSLog(@"%d", i % 11);
self.view7.backgroundColor = self.array[i ++ % 11];
//NSLog(@"%d", i % 11);
self.view8.backgroundColor = self.array[i ++ % 11];
// NSLog(@"%d", i % 11);
self.view9.backgroundColor = self.array[i ++ % 11];
// NSLog(@"%d", i % 11);
self.view10.backgroundColor = self.array[i ++ % 11];
// NSLog(@"%d", i % 11);
self.view11.backgroundColor = self.array[i ++ % 11];
j ++;
if (j > 10) {
j = 0;
}
i = j;
初级UI设计中的颜色渐变
最新推荐文章于 2025-01-04 00:00:00 发布