I've added UIScrollView in which added UIStackView in storyboard. I'm trying to add UIStackView having two UILabels dynamically in parent UIStackView Although i'm giving height of child view ,it takes all the space of parent UIStackView how do i solve this or any other way to achieve this?
My code is
func createSummaryView()
{
let labelSummary:UILabel = UILabel(frame: CGRectZero)
labelSummary.text = "Summary"
labelSummary.heightAnchor.constraintEqualToConstant(30).active = true
let summaryparentView:UIStackView = UIStackView(frame: CGRectZero)
summaryparentView.axis = .Vertical
summaryparentView.alignment = .Leading
summaryparentView.spacing = 1
let summaryViewWidth = width!-50
summaryparentView.heightAnchor.constraintEqualToConstant(180).active = true
//summaryparentView.heightAnchor.constraintEqualToAnchor(summaryparentView.heightAnchor, multiplier: 2).active = true
summaryparentView.addArrangedSubview(labelSummary)
for _ in 1...5
{
let viewParent:UIStackView = UIStackView(frame: CGRectZero)
viewParent.axis = .Horizontal
viewParent.widthAnchor.constraintEqualToConstant(summaryViewWidth).active = true
viewParent.heightAnchor.constraintEqualToConstant(30).active = true
viewParent.distribution = .FillEqually
let labelTitle:UILabel = UILabel()
let labelValue:UILabel = UILabel()
print("summary view width \(summaryViewWidth)")
labelTitle.text = "BUILD"
labelValue.text = "2012"
viewParent.addArrangedSubview(labelTitle)
viewParent.addArrangedSubview(labelValue)
summaryparentView.addArrangedSubview(viewParent)
summaryparentView.translatesAutoresizingMaskIntoConstraints = false
}
stackViewVertical.layoutMarginsRelativeArrangement = true
stackViewVertical.addArrangedSubview(summaryparentView)
stackViewVertical.translatesAutoresizingMaskIntoConstraints = false
}
where width is width = stackViewVertical.frame.size.width