0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Swift]セーフエリアの色を変える

Posted at

iOS11から導入されたセーフエリアの色を変えたい。

結論としては、色を直接変えるのではなくセーフエリアの上にUIViewを被せることで対応できる。
viewDidLoadなどに記述するとよい。

safeArea.swift
        if #available(iOS 11.0, *)
        {
            let topFrame: CGRect = CGRect(x: view.safeAreaInsets.left,
                                       y: view.safeAreaInsets.top,
                                       width: UIScreen.main.bounds.size.width,
                                       height: 44)
            let safeAreaOverlay: UIView = UIView()
            safeAreaOverlay.frame = topFrame
            safeAreaOverlay.backgroundColor = .green //変えたい対象の色
            view.addSubview(safeAreaOverlay)
        }
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?