ios9中 UIStackView的使用

UIStackView可以垂直或水平排布多个subview,
自动为每个subview创建和添加Auto Layout constraints.

1.添加subview
let logoImage:UIImageView = UIImageView(image: UIImage(named: "logo"))
logoImage.contentMode = .ScaleAspectFit
self.stackView.addArrangedSubview(logoImage)
UIView.animateWithDuration(0.25, animations: {
    self.stackView.layoutIfNeeded()
})

2.删除subview
self.stackView.removeArrangedSubview(logoView)

编程技巧