Search code examples
swiftxcodexibstackview

Swift stackview add subview in center


I use this code for view nib to stackview

for index in 0..<4 {
    let view = CategoryClass.createMyClassView()
    view.myLabel.text = "Hello World!"
    self.stackView.addArrangedSubview(view)
}

And I get below image :

enter image description here

But I want to add subview by category.xib height ( 40px per view ) not fill.

And set in center of parent

Like below :

enter image description here

Screenshot:

enter image description here


Solution

  • Please add Four label in Xib and after put in stackView and give spacing like 5, 10, 20 whatever you like 
    
    Please check screenshot and let me know if u have any problem related stackview i will help you
    

    enter image description here