[英]How to get a black statusbar on iPhone X on iOS 11
默認情況下,iPhone X上的狀態欄如下所示:
但我想實現這個目標:
我嘗試將preferredStatusBarStyle
設置為lightContent
但它只在將狀態欄后面的背景設置為黑色后才起作用。
為了修復圓角,我最后添加了另一個圓角的子視圖。
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
let roundedView = UIView(
frame: CGRect(
x: 0,
y: UIApplication.shared.statusBarFrame.height,
width: view.frame.width,
height: view.frame.height
)
)
roundedView.layer.cornerRadius = 10
roundedView.layer.masksToBounds = true
roundedView.backgroundColor = .white
view.addSubview(roundedView)
let label = UILabel(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 60))
label.text = "Black statusbar!"
label.textAlignment = .center
roundedView.addSubview(label)
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
我想知道這是否是最好的方法..必須有更好的方法來實現這一目標。
UPDATE
這是一個可怕的想法,因為:
請勿掩蓋或特別注意按鍵顯示功能。 不要試圖通過在屏幕的頂部和底部放置黑條來隱藏設備的圓角,傳感器外殼或用於訪問主屏幕的指示器。 不要使用括號,邊框,形狀或說明文字等視覺裝飾來特別注意這些區域。
視圖頂部的圓角可能看起來不錯,但您必須在代碼中添加例外以確保其他iPhone上不顯示圓角。 你需要把它放在你所有的ViewControllers / Storyboard中。這不是那么好。
視圖底部的圓角將在屏幕截圖中顯示為直線,但頂部的角(手動設置)不會。 當用戶分享您的應用時,這將是丑陋的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.