If you want to provide backgroundColor, CornerRadius and Shadow to StackView:
extension UIStackView {
func insertCustomizedViewIntoStack(background: UIColor, cornerRadius: CGFloat, shadowColor: CGColor, shadowOpacity: Float, shadowRadius: CGFloat) {
let subView = UIView(frame: bounds)
subView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
subView.layer.cornerRadius = cornerRadius
subView.backgroundColor = background
subView.layer.shadowColor = shadowColor
subView.layer.shadowOpacity = shadowOpacity
subView.layer.shadowOffset = .zero
subView.layer.shadowRadius = shadowRadius
insertSubview(subView, at: 0)
}
}
If you want to provide backgroundColor, CornerRadius , borderColor and border width to StackView:
extension UIStackView {
func insertViewIntoStack(background: UIColor, cornerRadius: CGFloat, borderColor: CGColor, borderWidth: CGFloat) {
let subView = UIView(frame: bounds)
subView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
subView.layer.cornerRadius = cornerRadius
subView.backgroundColor = background
subView.layer.borderColor = borderColor
subView.layer.borderWidth = borderWidth
insertSubview(subView, at: 0)
}
}