UIKit - topLayoutGuide, bottomLayoutGuideとは
実はあんまり分かっていなかったので確認。
だいぶはしょって説明すると、
topLayoutGuideは、ステータスバーやナビゲーションバーなどの上部のUIを考慮してレイアウトするもので、
bottomLayoutGuideは、タブバーなどの下部のUIを考慮してレイアウトするものですね。
下のように書くと、ナビゲーションバーやステータスバー、タブバーに
かぶらないないようにレイアウトしてくれます。
var btn: UIButton! var label: UILabel! override func updateViewConstraints() { btn.topAnchor.constraintEqualToAnchor(self.topLayoutGuide.bottomAnchor, constant: 0).active = true btn.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor, constant: 100).active = true label.bottomAnchor.constraintEqualToAnchor(self.bottomLayoutGuide.topAnchor, constant: 0).active = true label.leadingAnchor.constraintEqualToAnchor(self.view.leadingAnchor, constant: 100).active = true super.updateViewConstraints() }