Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
@IBAction func buttonAction(_ sender: AnyObject) {
let newView = UIView(frame: CGRect(x: 0, y: 0, width: 240, height: 128))
newView.heightAnchor.constraint(equalToConstant: 128)
newView.widthAnchor.constraint(equalToConstant: 240)
newView.backgroundColor = UIColor.green
stackOutlet.addArrangedSubview(newView)
stackOutlet.heightAnchor.constraint(equalToConstant: stackOutlet.frame.size.height + 128)
print(stackOutlet.subviews.count)
The number of subviews is increasing, but nothing is changing on the screen. I suspect that my StackView doesnt resize properly right ?
Nevermind I found a solution :
newView.widthAnchor.constraint(equalToConstant: 240).isActive = true
newView.heightAnchor.constraint(equalToConstant: 128).isActive = true
You need the .isActive = true
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.