如何在图像的顶部和左侧制作阴影?

时间:2017-01-14 06:00:10

标签: ios swift swift3

我在图像的右下方添加了一个阴影。

代码是

func addShadow(image: UIImage, blursize: CGFloat) -> UIImage {
   let shadowColor = UIColor(white:0, alpha: 0.8).cgColor
   let context = CGContext(data: nil, width: Int(image.size.width + blursize), height: Int(image.size.height + blursize), bitsPerComponent: image.cgImage!.bitPerComponent, bytesPerRow: 0, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
   context.setShadow(offset: CGSize(width: 0, height: 0), blur: blursize, color: shadowColor)
   context.draw(image.cgImage!, in: CGRect(x:0,y:blursize,width:image.size.width, height: image.size.height), byTiling: false)
   return UIImage(cgImage: context.makeImiage()!)
}

我需要在图像的左侧和顶部添加阴影。 enter image description here

我该怎么办?

0 个答案:

没有答案