I want to create a UICollectionView with a custom header in Code. Therefore i created a Subclass of UICollectionViewCell to describe my custom header. I want to display five labels in my header in a horizontal line. Therefore I created five labels and add them inside a stackView. The stackview show my labels filled equally. So far everything perfect.
Label1 Label2 Label3 Label4 Label5
//Label 1
let votesLabel: UILabel = {
let label = UILabel()
let attributedText = NSMutableAttributedString(string: "Votes", attributes: [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 12) ])
attributedText.append(NSAttributedString(string: "\n 0", attributes: [NSForegroundColorAttributeName: UIColor.lightGray, NSFontAttributeName: UIFont.systemFont(ofSize: 14)]))
label.attributedText = attributedText
// label.text = "11\nvotes"
label.textAlignment = .center
label.numberOfLines = 0
return label
}()
// label 2 ... 5
// creating the subview and add the labels to my subview
addSubview(topDividerView)
let stackView = UIStackView(arrangedSubviews: [ votesLabel, and the other 4 labels])
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .horizontal
stackView.distribution = .fillEqually
addSubview(stackView)
// add stackView to my view
stackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
stackView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
stackView.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
stackView.heightAnchor.constraint(equalToConstant: 50).isActive = true
Now I want to add separate vertical lines between these labels like that:
Label1 | Label2 | Label3 | Label4 | Label5
I created a UIView but can't add this view between the labels. Can anyone help me please. Thanks