3

I've a horizontal stackview which has a stackview as a subview with 2 labels. Alignment & Distribution are set to Fill in Xcode Attribute Inspector. I want to display 7 subview stacks inside the stack view with 4 in first row and 3 in second row using only one horizontal stackview. I have loaded first row. When I add 5th element, it is appearing in 1st row instead of 2nd row. Number of subviews changes dynamically. If there are 3 elements it should only display only one row. If more than 5, it should display in 2 rows.Below is the code.

if let viewInfos = TestViewController.viewInfos{
            let dataNib = UINib(nibName: "InfoStackView", bundle: frameworkBundle)
            for viewInfo in viewInfos {
                let infoStackView = dataNib.instantiateWithOwner(nil, options: nil)[0] as! InfoStackView
                infoStackView.addInfoToStackView(viewInfo: viewInfo)
                self.InfoStackView.addArrangedSubview(infoStackView)
            }
        }

    Inside addInfoToStackView method, i add the label for each stackview 

Above code adds stackview as subviews horizontally. I want to restrict 4 in first row and 3 in next row. Please help me how do this.

Zoombie
  • 31
  • 3
  • Best if you get started and come back if you get stuck on something. – Matt Cremeens Jun 27 '16 at 18:55
  • @MattCremeens : I've already started. I have loaded first row. When I add 5th element, it is appearing in 1st row instead of 2nd row. No of subviews changes dynamically. If there are 3 elements it should only display only one row. If more than 5, it should display in 2 rows. Updated question. Thanks :) – Zoombie Jun 27 '16 at 19:01
  • In that case, would you mind posting your code? – Matt Cremeens Jun 27 '16 at 19:02
  • `if let viewInfos = TestViewController.viewInfos{ let dataNib = UINib(nibName: "InfoStackView", bundle: frameworkBundle) for viewInfo in viewInfos { let infoStackView = dataNib.instantiateWithOwner(nil, options: nil)[0] as! InfoStackView infoStackView.addInfoToStackView(viewInfo: viewInfo) self.InfoStackView.addArrangedSubview(infoStackView) } }` Inside addInfoToStackView method, i add the label for each stackview – Zoombie Jun 27 '16 at 19:09
  • Great. I would suggest formatting it and placing it in your question and then mention what you expected that code to do and what it is doing instead. – Matt Cremeens Jun 27 '16 at 19:15
  • @MattCremeens: Done – Zoombie Jun 27 '16 at 19:26
  • @MattCremeens: Can you please help now?. – Zoombie Jun 27 '16 at 19:39
  • Unfortunately, this is outside of my expertise. I just wanted to help you edit your question to maximize your chance of getting some help from others. – Matt Cremeens Jun 27 '16 at 19:41

0 Answers0