I'd like to add blur effect in UIimage, not UIImage View. I can add blur effect into uiimage view just like this:
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = img.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
img.addSubview(blurEffectView)
But, I really want to add into uiimage. Because I have to draw image with text. so here is my function:
func textToImageWithPhoto(drawText text: NSString, inImage image: UIImage, atPoint point: CGPoint) -> UIImage {
let scale = UIScreen.main.scale
UIGraphicsBeginImageContextWithOptions(CGSize.init(width: 375, height: 375), false, scale)
image.draw(in: CGRect(origin: CGPoint.init(x: 0, y: -100), size: CGSize(width: 375, height: 375*1.5)))
let rect = CGRect(origin: CGPoint.init(x: 0, y: 187.5 - 150/2 ), size: CGSize.init(width: 375, height: 375))
text.draw(in: rect, withAttributes: textFontAttributes)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
self.saveData(img: newImage!, text: self.quotesTxt.text!) //SAVE CORE DATA
return newImage!
}
And is there some way to add blur effect within draw function?