UIView*colorView = [[UIViewalloc] init];
[colorView setFrame:CGRectMake(20,160,self.view.frame.size.width -40,self.view.frame.size.height -320)];[self.view addSubview:colorView];
CAGradientLayer*gradient = [CAGradientLayerlayer];gradient.frame = colorView.bounds;
gradient.colors = [NSArrayarrayWithObjects: (id)[UIColorcolorWithRed:0green:143/255.0blue:234/255.0alpha:1.0].CGColor, (id)[UIColorcolorWithRed:0green:173/255.0blue:234/255.0alpha:1.0].CGColor, (id)[UIColorwhiteColor].CGColor,nil];
[colorView.layer addSublayer:gradient];
使用CAGradientLayerlayer 就可以!
可以通过设置
gradient.startPoint =CGPointMake(0,0);
gradient.endPoint =CGPointMake(1,1);
gradient.locations = @[@0.0, @0.2, @0.5];
这三个属性 来 确定渐变方向
网友评论