Last active
May 28, 2020 08:03
-
-
Save martinpilch/d1f95077a492e97e14bc3d84121995b4 to your computer and use it in GitHub Desktop.
Rounded corners for UIView in modern way
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
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