Last active
January 27, 2018 16:19
-
-
Save niftycode/f8f460d2d4c4a0879d7e to your computer and use it in GitHub Desktop.
This playground project shows how to modify an image with CALayer (Swift 4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: # 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