Created
May 22, 2018 14:31
-
-
Save AlexFlyce/5b35b1ae22232117b326973dfdeeef7b to your computer and use it in GitHub Desktop.
ART001-circularImage.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
extension UIImage { | |
class func circularImage(from image: UIImage, size: CGSize) -> UIImage? { | |
let scale = UIScreen.main.scale | |
let circleRect = CGRect(x: 0, y: 0, width: size.width * scale, height: size.height * scale) | |
UIGraphicsBeginImageContextWithOptions(circleRect.size, false, scale) | |
let circlePath = UIBezierPath(roundedRect: circleRect, cornerRadius: circleRect.size.width/2.0) | |
circlePath.addClip() | |
image.draw(in: circleRect) | |
if let roundImage = UIGraphicsGetImageFromCurrentImageContext() { | |
return roundImage | |
} | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment