How to get a black statusbar on iPhone X on iOS 11

后端 未结 1 1606
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 17:04

By default the statusbar on an iPhone X looks like this:

But I would like to achieve this:

I tried setting the preferredStatusBarStyle

1条回答
  •  有刺的猬
    2021-02-13 17:18

    Safe Area Layout is a solution to your problem.

    I tried following the solution in my existing projects and it works fine.

    • Set black background color (or what ever you want) to main view of your view controller.
    • Now add child view (with white background) and set its constraints relative to Safe Area Layout (or follow Top and bottom layout guide if Xcode version is below 9).
    • Consider this child view (with white background) as a main view and process further design with it.

    Here is sample snapshot with result, By enabling or disabling Safe Area layout, I tested and implemented.

    FYI: In these snapshots, main view has red background and child view has blue background color.

    Safe Area Layout:

    AutoLayout

    0 讨论(0)
提交回复
热议问题