有什么解决方法吗
1
pptk OP 已解决
//绘制渐变 UIColor *firstColor = [[UIColor alloc]initWithCGColor:(CGColorRef)self.bgLayer.colors.firstObject]; UIColor *lastColor = [[UIColor alloc]initWithCGColor:(CGColorRef)self.bgLayer.colors.lastObject]; //创建一个 RGB 的颜色空间 CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); //定义渐变颜色数组 CGFloat colors[] = { firstColor.qmui_red, firstColor.qmui_green, firstColor.qmui_blue, 1.00, lastColor.qmui_red, lastColor.qmui_green, lastColor.qmui_blue, 1.00 }; CGGradientRef _gradient = CGGradientCreateWithColorComponents(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4)); UIGraphicsBeginImageContextWithOptions(self.preImage.size, NO, self.preImage.scale); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextInspectContext(context); CGPoint start = CGPointMake(self.preImage.size.width/2, 0); CGPoint end = CGPointMake(self.preImage.size.width/2, self.preImage.size.height); CGContextDrawLinearGradient(context, _gradient, start, end, kCGGradientDrawsBeforeStartLocation); CGImageRef imageRef = self.preImage.CGImage; CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef,CGRectMakeWithSize(self.preImage.size)); CGContextDrawImage(context, CGRectMakeWithSize(self.preImage.size), subImageRef); UIImage *imageOut = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); |