初级UI设计中的颜色渐变

<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;
    




                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值