Reputation: 515
I'm trying to understand how addArrangedSubview is working so I tried with a dummy project. Here's my VC :
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var stackOutlet: UIStackView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let newView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
newView.backgroundColor = UIColor.darkGray
let newView2 = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
newView2.backgroundColor = UIColor.blue
stackOutlet.addArrangedSubview(newView)
stackOutlet.addArrangedSubview(newView2)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
When I launch the app, nothing is appearing. I think I have to set some constraints in the stackView?
Upvotes: 2
Views: 3192
Reputation: 515
Ok so for everyone sakes : you need to use this =
mapView.heightAnchor.constraint(equalToConstant: 200).isActive = true
mapView.widthAnchor.constraint(equalToConstant: 200).isActive = true
Upvotes: 5