Created
October 13, 2018 05:51
-
-
Save npu3pak/eaa0f7116c0e59612d6a90085666062b to your computer and use it in GitHub Desktop.
Round cornered view with border
This file contains hidden or 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 UIView { | |
func configureBorder(_ roundCorners:UIRectCorner, cornerRadius: CGFloat, borderColor: UIColor, borderWidth: CGFloat) { | |
let path = UIBezierPath(roundedRect: bounds, | |
byRoundingCorners: roundCorners, | |
cornerRadii: CGSize(width: cornerRadius, height: cornerRadius)) | |
let mask = CAShapeLayer() | |
mask.path = path.cgPath | |
mask.borderColor = UIColor.white.cgColor | |
layer.mask = mask | |
let border = CAShapeLayer() | |
border.path = path.cgPath | |
border.lineWidth = borderWidth | |
border.strokeColor = borderColor.cgColor | |
border.fillColor = UIColor.clear.cgColor | |
layer.addSublayer(border) | |
clipsToBounds = true | |
} | |
} | |
let view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) | |
view.backgroundColor = UIColor.red | |
view.configureBorder([.bottomLeft, .bottomRight], cornerRadius: 30, borderColor: .green, borderWidth: 4) | |
Author
npu3pak
commented
Oct 13, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment