Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This playground project shows how to modify an image with CALayer (Swift 4)
//: # CALayer Example 2
import UIKit
import PlaygroundSupport
// view with white background color
var backgroundView = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 400))
backgroundView.backgroundColor = UIColor.white
PlaygroundPage.current.liveView = backgroundView
var imageView = UIView(frame: CGRect(x: 0, y: 0, width: 250, height: 250))
imageView.center = backgroundView.center
let myImage = UIImage(named: "nature.jpg")
backgroundView.addSubview(imageView)
imageView.layer.contents = myImage?.cgImage
imageView.layer.borderWidth = 4
imageView.layer.borderColor = UIColor.green.cgColor
imageView.layer.cornerRadius = imageView.bounds.height/2.0
imageView.layer.masksToBounds = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.