iOS开发UI篇——Core Animation核心动画CAGradientLayer(实现渐变色等)简介
一、CAGradientLayer实现渐变色(设置tableView背景为渐变色)
[self.view setBackgroundColor:[UIColor whiteColor]]; UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0,0, mainWidth, mainHeight-64)]; table.separatorStyle = UITableViewCellSeparatorStyleNone; //当设置layer渐变色时,一定要把view的颜色设置为透明,要不会被覆盖 [table setBackgroundColor:[UIColor clearColor]]; //设置颜色值 UIColor *_inputColor0 = [UIColor redColor]; UIColor *_inputColor1 = [UIColor orangeColor]; //1.创建layer CAGradientLayer *redLayer2 = [CAGradientLayer new]; //2.可以添加多种颜色,这里只设置两种颜色 redLayer2.colors = @[(__bridge id)_inputColor1.CGColor, (__bridge id)_inputColor0.CGColor]; //3.设置渐变颜色方向,左上点为(0,0), 右下点为(0,1) redLayer2.startPoint = CGPointMake(0, 0); redLayer2.endPoint = CGPointMake(0, 1); redLayer2.frame = self.secondTable.frame; //4.将layer添加到视图上 [self.view.layer addSublayer:redLayer2]; [self.view addSubview:table];
将来的自己,会感谢现在不放弃的自己!