How to add SubView to a horizontal StackView programmatically to create Stripes?
问题 I have a collectionView Cell with a StackView in it. class OuterCollectionViewCell: UICollectionViewCell { @IBOutlet weak var stackView: UIStackView! override init(frame: CGRect) { super.init(frame: frame) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) for i in 1...30 { let tick = UIView() if i % 2 == 0 { tick.backgroundColor = UIColor.red } else { tick.backgroundColor = UIColor.clear } tick.tag = i tick.heightAnchor.constraint(equalTo: self.heightAnchor, constant: 0