我用这种方法得到渐变图像
func gradient(size:CGSize,color:[UIColor]) -> UIImage?{
//turn color into cgcolor
let colors = color.map{$0.cgColor}
//begin graphics context
UIGraphicsBeginImageContextWithOptions(size, true, 0.0)
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}
// From now on, the context gets ended if any return happens
defer {UIGraphicsEndImageContext()}
//create core graphics context
let locations:[CGFloat] = [0.0,1.0]
guard let gredient = CGGradient.init(colorsSpace: CGColorSpaceCreateDeviceRGB(), colors: colors as NSArray as CFArray, locations: locations) else {
return nil
}
//draw the gradient
context.drawLinearGradient(gredient, start: CGPoint(x:0.0,y:size.height), end: CGPoint(x:size.width,y:size.height), options: []) …Run Code Online (Sandbox Code Playgroud) 我希望在我的ARKit项目中添加项目的照明类似于真实世界的对象.请解释一下如何实现这个目标?谢谢