Created
July 19, 2014 06:31
-
-
Save bitops/11c0d7c1a5546473c7c7 to your computer and use it in GitHub Desktop.
Port of accepted answer to http://stackoverflow.com/questions/10563986/uiimage-with-rounded-corners to Swift.
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
// get your image | |
var image = UIImage(named: "image.jpg") | |
// begin a new image | |
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, UIScreen.mainScreen().scale) | |
// add a clip in the shape of a rounded rectangle | |
UIBezierPath(roundedRect: imageView.bounds, cornerRadius: 10.0).addClip() | |
// draw the image in the view | |
image.drawInRect(imageView.bounds) | |
// set the image | |
imageView.image = UIGraphicsGetImageFromCurrentImageContext() | |
// clean up | |
UIGraphicsEndImageContext() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//This makes an ImageView rounded....
imageView.layer.cornerRadius = imageView.frame.size.width / 2
imageView.clipsToBounds = true