Reputation: 4646
I am adding labels as subview to UIstackview using arrangedSubView property.
what happens is that if I keep Stackview axis horizontal, I get one horizontal strip of UILabels
label1 label2 label3 label4.....
if I keep it vertical, I get a vertical strip of UILabels like below
label1
label2
label3
and so on
But what I am trying to achieve is this
label1, label2(if it fits) otherwise take it below
label3, label4
label5 and so on
presently my code is this
uiLabel1.numberOfLines = 1
uiLabel1.backgroundColor = THEMECOLOR
uiLabel1.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption1)
uiLabel1.textColor = topicColor
uiLabel1.layer.cornerRadius = (CGFloat)(5.0)
uiLabel1.layer.masksToBounds = true
uiLabel1.sizeToFit()
uiLabel1.userInteractionEnabled = true
self.dynamicStackView.addArrangedSubview(uiLabel1)
Upvotes: 2
Views: 552
Reputation: 6191
I believe Flow Layout of the UICollectionView
is what you need. Have a look at the link here
Upvotes: 1