Skip to content

Instantly share code, notes, and snippets.

View flaksp's full-sized avatar
🍏

Petr Flaks flaksp

🍏
View GitHub Profile
@brownsoo
brownsoo / rounded_uiimage.swift
Created April 10, 2018 05:52
Cut UIImage with rounded rectangle or circle
public extension UIImage {
func round(_ radius: CGFloat) -> UIImage {
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let renderer = UIGraphicsImageRenderer(size: rect.size)
let result = renderer.image { c in
let rounded = UIBezierPath(roundedRect: rect, cornerRadius: radius)
rounded.addClip()
if let cgImage = self.cgImage {
UIImage(cgImage: cgImage, scale: self.scale, orientation: self.imageOrientation).draw(in: rect)
}