How can I add stickers to an image in Swift?

Here's the easy way.

  1. have a UIView as a parent, let's say stickerView
  2. add image to stickerView
  3. add stickers to stickerView
  4. save a snapshot of stickerView

Here's the code to snapshot UIView,

extension UIImage {
    class func imageWithView(view: UIView) -> UIImage {
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0)
        view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
        let img = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return img
    }
}

Usage

let snapshotImage = UIImage.imageWithView(stickerView)

Tags:

Ios

Iphone

Swift