我正在尝试将 UIStackView 介绍分成三个单独的 subview ,并用虚线将它们分开。我知道您可以在 UIStackView 上设置间距,但据我所知,您无法将该间距更改为虚线。
基本上,我希望我的三个 subview 能够在不同的设备尺寸上正确缩放,但虚线在它们之间总是很小。为了清楚起见,我试图实现的结果如下所示:
希望有人能指出正确的方向,提前谢谢!
Best Answer-推荐答案 strong>
您可以将 3 个 View 限制为相等的宽度,然后添加几个限制为恒定宽度的分隔 View 。
let stackView = UIStackView()
stackView.axis = .horizontal
self.view.addSubview(stackView)
let view1 = UIView()
view1.backgroundColor = .red
stackView.addArrangedSubview(view1)
let separator1 = UIView()
separator1.backgroundColor = .black
stackView.addArrangedSubview(separator1)
separator1.widthAnchor.constraint(equalToConstant: 1).isActive = true
let view2 = UIView()
view2.backgroundColor = .green
stackView.addArrangedSubview(view2)
view2.widthAnchor.constraint(equalTo: view1.widthAnchor, multiplier: 1).isActive = true
let separator2 = UIView()
separator2.backgroundColor = .black
stackView.addArrangedSubview(separator2)
separator2.widthAnchor.constraint(equalToConstant: 1).isActive = true
let view3 = UIView()
view3.backgroundColor = .blue
stackView.addArrangedSubview(view3)
view3.widthAnchor.constraint(equalTo: view1.widthAnchor, multiplier: 1).isActive = true
关于ios - 用虚分隔线将stackview分成三个 subview ?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/47457233/
|