Skip to content

Instantly share code, notes, and snippets.

@artemnovichkov
Last active February 11, 2017 07:31
Show Gist options
  • Save artemnovichkov/195492c90a4153a7df2d679eb2ccd0b3 to your computer and use it in GitHub Desktop.
Save artemnovichkov/195492c90a4153a7df2d679eb2ccd0b3 to your computer and use it in GitHub Desktop.
Extension for rounded corners in UIView. Warning: make sure that your UIView already has correct frame.
import UIKit
extension UIView {
func round(with radius: CGFloat, corners: UIRectCorner) {
let roundedPath = UIBezierPath(roundedRect: bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
let maskLayer = CAShapeLayer()
maskLayer.path = roundedPath.cgPath
layer.mask = maskLayer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment