如果有两个UIColors
UIColor *colr1 = [UIColor colorWithRed:0 green:0.553 blue:0.416 alpha:1.0];
UIColor *colr2 =[UIColor colorWithRed:0 green:0.341 blue:0.263 alpha:1.0];
如何从上到下制作视图(myView with frame CGRectMake(0,0,320,568))这两种颜色的背景颜色渐变。 请为此提供一些代码(iOS7)。谢谢你。
答案 0 :(得分:2)
尝试
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = yourView.bounds;
UIColor *colr1 = [UIColor colorWithRed:0 green:0.553 blue:0.416 alpha:1.0];
UIColor *colr2 =[UIColor colorWithRed:0 green:0.341 blue:0.263 alpha:1.0];
gradient.colors = [NSArray arrayWithObjects:(id)[colr1 CGColor], (id)[colr2 CGColor], nil];
[yourView.layer insertSublayer:gradient atIndex:0];