Skip to content

Instantly share code, notes, and snippets.

@martinpilch
Last active May 28, 2020 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinpilch/d1f95077a492e97e14bc3d84121995b4 to your computer and use it in GitHub Desktop.
Save martinpilch/d1f95077a492e97e14bc3d84121995b4 to your computer and use it in GitHub Desktop.
Rounded corners for UIView in modern way
import UIKit
extension CACornerMask {
static var noCorners: CACornerMask { return [] }
static var topLeftCorner: CACornerMask { return .layerMinXMinYCorner }
static var topRightCorner: CACornerMask { return .layerMaxXMinYCorner }
static var bottomLeftCorner: CACornerMask { return .layerMinXMaxYCorner }
static var bottomRightCorner: CACornerMask { return .layerMaxXMaxYCorner }
static var topCorners: CACornerMask { return [.topLeftCorner, .topRightCorner] }
static var bottomCorners: CACornerMask { return [.bottomLeftCorner, .bottomRightCorner] }
static var leftCorners: CACornerMask { return [.topLeftCorner, .bottomLeftCorner] }
static var rightCorners: CACornerMask { return [.topRightCorner, .bottomRightCorner] }
}
extension UIView {
func set(corners: CACornerMask, radius cornerRadius: Radius) {
layer.cornerRadius = cornerRadius
layer.maskedCorners = corners
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment