I need to adding views to stackview by using "for in" loops. However, the views in the stackview are overlap with each other.
addplantoPlanArray samply init a view and add it to the PlanArray, then using "for in" loop to add each view in that Array into the stackview.
here is the code:
self.addPlantoPlanArray(IDText: "123123", Name: "abc", Participants: "abc", Duration: "abc", Price: "abc")
self.addPlantoPlanArray(IDText: "14123123", Name: "123123", Participants: "123123", Duration: "123123", Price: "123123")
for plan in PlanArray {
stackview.addArrangedSubview(plan)
}
stackview.axis = .horizontal
stackview.distribution = .fillEqually
stackview.spacing = 274
view.addSubview(stackview)
The result is that the second view is totally overlap on the first one.
The constrains for the stackview:
view.addSubview(PlanStackView)
PlanStackView.translatesAutoresizingMaskIntoConstraints = false
let stackviewTop = NSLayoutConstraint(item: PlanStackView, attribute: .top, relatedBy: .equal, toItem: view, attribute: .top, multiplier: 1, constant: 380)
let stackviewLeading = NSLayoutConstraint(item: PlanStackView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 10)
view.addConstraints([stackviewTop, stackviewLeading])
No constrains for the instance view, it is init with default frame. here is the init method for the instance class:
init(PlanDefaultIDText: String, PlanNameText: String, PlanParticipantsText: String, PlanDurationText: String, PlanPriceText: String) {
super.init(frame: CGRect(x: 0, y: 0, width: 264, height: 150))