ios 给一个页面或者控件添加渐变颜色的属性

2018-12-01  本文已影响0人  elephant0001

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

这三个属性     来 确定渐变方向

上一篇 下一篇

猜你喜欢

热点阅读