UIKit is making me feel like extremely frustrated. I have this little piece of code in Xcode playgrounds:
let views = [UIView(), UIView(), UIView()]
for view in views {
view.backgroundColor = UIColor.blueColor()
view.bounds.size = CGSize(width: 40, height: 40)
}
let stack = UIStackView(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
stack.backgroundColor = UIColor.redColor()
stack.addArrangedSubview(views[0])
stack.addArrangedSubview(views[1])
stack.addArrangedSubview(views[2])
stack.axis = .Horizontal
stack.distribution = .Fill
stack.alignment = .Center
stack.spacing = 5
But no matter which distribution strategy I chose, I always end up with this.My expectation is to see three squares spread evenly in the stack. Not all of them on top of each other.
It seem auto layout in stack view is not laying items out properly.
But why?