LoginSignup
1
2

More than 5 years have passed since last update.

画面下のバナーをSafe area対応したときのコード

Posted at

UILayoutGuideを使い分けてあとはautolayoutで調整したらできた。

// bannerViewは基本的な初期化が終わったバナー
let guide:UILayoutGuide
if #available(iOS 11, *) {
    guide = self.view.safeAreaLayoutGuide
} else {
    guide = self.view.layoutMarginsGuide
}

NSLayoutConstraint.activate([
    bannerView!.heightAnchor.constraint(equalToConstant: bannerView!.frame.height),
    bannerView!.centerXAnchor.constraint(equalTo: guide.centerXAnchor),
    bannerView!.bottomAnchor.constraint(equalTo: guide.bottomAnchor)
])
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2