【发布时间】:2018-08-02 11:07:09
【问题描述】:
我有一个堆栈视图,其中有 3 个项目垂直对齐。现在我创建了一个Uiview 给它一个边框,并在stackview 中添加它以将其显示为带有半径角的彩色背景。
我成功地创建了一个视图并将其附加到UIStackview。但它似乎涵盖了UIStackView 的所有其他排列的子视图。而我想把其他子视图放在前面。请帮我。这是下面的代码:
extension UIStackView {
override open var backgroundColor: UIColor? {
get {
return super.backgroundColor
}
set {
super.backgroundColor = newValue
let tag = -9999
for view in subviews where view.tag == tag {
view.removeFromSuperview()
}
let subView = UIView()
subView.tag = tag
subView.backgroundColor = newValue
subView.translatesAutoresizingMaskIntoConstraints = false
subView.layer.cornerRadius = 5
subView.layer.masksToBounds = true
subView.layer.borderColor = CommonUtils.hexStringToUIColor(hex: "#C2C2C2").cgColor
subView.layer.borderWidth = 0.35
self.addSubview(subView)
subView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
subView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
subView.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
subView.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
}
}
}
【问题讨论】:
-
subView.layer.zPosition = -1
标签: ios swift uiview uistackview