一:话不多说,先上图
按钮渐变色
二:代码
//1实现渐变色
CAGradientLayer *gradient = [CAGradientLayer layer];
//设置开始和结束位置(设置渐变的方向)
gradient.startPoint = CGPointMake(0, 0);
gradient.endPoint = CGPointMake(1, 0);
gradient.frame = CGRectMake(0,0,_preparatio.width,_preparatio.height);
gradient.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithHexString:@"#FF6EFD"].CGColor,(id)[UIColor colorWithHexString:@"#FF8D4D"].CGColor,nil];
//2把渐变色生成为Image
UIGraphicsBeginImageContextWithOptions(_preparatio.bounds.size, _preparatio.opaque, 0.0);
[gradient renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//3设置view背景色
view.backgroundColor = [UIColor colorWithPatternImage:img];
网友评论