Last active
December 20, 2021 08:33
-
-
Save atsushi130/fa8cbf1520fbba52cd212541c4921f57 to your computer and use it in GitHub Desktop.
RoundedView
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
final class RoundedView: UIView { | |
private let cornerRadius: CGFloat | |
private let cornerCurve: CALayerCornerCurve | |
private let color: UIColor | |
init(radius: CGFloat = 50, cornerCurve: CALayerCornerCurve, color: UIColor) { | |
self.cornerRadius = radius | |
self.cornerCurve = cornerCurve | |
self.color = color | |
super.init(frame: .zero) | |
self.commonInit() | |
} | |
... | |
private func commonInit() { | |
self.layer.cornerRadius = self.cornerRadius | |
self.layer.cornerCurve = self.cornerCurve | |
self.backgroundColor = self.color | |
} | |
} | |
let continuousView = RoundedView(cornerCurve: .continuous, color: .red) | |
self.view.addSubview(continuousView) | |
continuousView.translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
continuousView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), | |
continuousView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor), | |
continuousView.widthAnchor.constraint(equalToConstant: 160), | |
continuousView.heightAnchor.constraint(equalTo: continuousView.widthAnchor) | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment