I have an array of string and for each string value, I want to create a UILabel to display the text that means if I have 10 stings in the array, i want to have 10 labels with the string name. I am doing this programmaticalyy but since, it does not work and nothing is shown. This is what I have tried
let const: [String] = ["Central Cooling Unit", "Split Cooling Unit", "Oven", "Refridgerator", "Dish Washer"]
var checkBox: BEMCheckBox!
var checkLabel: DefaultLabel!
var checkboxStack: DefaultStackView?
fileprivate func setupButton() {
const.forEach { (title) in
checkBox = BEMCheckBox()
checkBox.translatesAutoresizingMaskIntoConstraints = false
checkBox.tintColor = UIColor.ZAMA.offWhite
checkBox.onCheckColor = UIColor.ZAMA.primary
checkBox.onFillColor = UIColor.ZAMA.tabColor
checkBox.onTintColor = UIColor.ZAMA.primary
checkBox.onAnimationType = .flat
checkBox.heightAnchor.constraint(equalToConstant: 25).isActive = true
checkBox.widthAnchor.constraint(equalToConstant: 25).isActive = true
checkLabel = UILabel()
checkLabel.text = title
checkLabel.textColor = .black
checkLabel.fontSize = 15
checkboxStack = UIStackView(arrangedSubviews: [centralCoolingCheckbox, centralCoolingText])
checkboxStack?.axis = .horizontal
checkboxStack?.spacing = 4
checkboxStack?.alignment = .fill
checkboxStack?.distribution = .fill
}
}
fileprivate func layout() {
view.addSubview(scrollView)
hideKeyboardWhenTappedAround()
setupButton()
stack = UIStackView(arrangedSubviews: [checkboxStack ?? DefaultStackView()])
stack.axis = .vertical
stack.distribution = .fillEqually
stack.spacing = 8
view.addSubview(stack)
stack.anchor(top: contentView.topAnchor, left: contentView.leftAnchor, bottom: nil, right: contentView.rightAnchor, paddingTop: 4, paddingLeft: 8, paddingBottom: 0, paddingRight: 8, width: 0, height: 0, enableInsets: false)
}
layout() is then called in viewDidLoad
