我想知道如何使用Swift來實現比youtube在其新應用(材質設計)中使用的navbar顏色更暗的狀態欄顏色。Youtube Style Swift中的Navbar導航
編輯
我希望新的應用設計的設計。不是舊的。這與僅更改狀態欄文本顏色無關。因此,這曾經旋鈕暗示其重複沒有理解能力
我想知道如何使用Swift來實現比youtube在其新應用(材質設計)中使用的navbar顏色更暗的狀態欄顏色。Youtube Style Swift中的Navbar導航
編輯
我希望新的應用設計的設計。不是舊的。這與僅更改狀態欄文本顏色無關。因此,這曾經旋鈕暗示其重複沒有理解能力
所以我想通了,我要在導航欄添加一個子視圖,然後添加紅色暗的陰影作爲視圖的背景。如果您的導航欄顏色在整個應用程序中相同,或者可以添加到視圖控制器中以使其不同,則可以在UINavigationClass
中使用此功能。
您可以更改YouTube等狀態欄的背景是這樣的:
的AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Step 1
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window?.makeKeyAndVisible()
//Step 2
UINavigationBar.appearance().barTintColor = UIColor.rgb(230, green: 32, blue: 32)
application.statusBarStyle = .LightContent
// Step 3
let statusBarBackgroundView = UIView()
statusBarBackgroundView.backgroundColor = UIColor.rgb(194, green: 31, blue: 31)
window?.addSubview(statusBarBackgroundView)
window?.addConstraintsWithFormat("H:|[v0]|", views: statusBarBackgroundView)
window?.addConstraintsWithFormat("V:|[v0(20)]", views: statusBarBackgroundView)
return true
}
extension UIColor {
static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 1)
}
}
extension UIView {
func addConstraintsWithFormat(format: String, views: UIView...) {
var viewsDictionary = [String: UIView]()
for(index, view) in views.enumerate() {
let key = "v\(index)"
view.translatesAutoresizingMaskIntoConstraints = false
viewsDictionary[key] = view
}
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
}
}
結果
的可能的複製[怎麼辦我在Swift 2/iOS 9中正確地更改狀態欄樣式?](h ttp://stackoverflow.com/questions/32674315/how-do-i-properly-change-my-status-bar-style-in-swift-2-ios-9) – MQLN
你可能想通過閱讀這個答案: http://stackoverflow.com/a/19585104/433373 –
對不起,我的意思是這個更好:http://stackoverflow.com/a/18855464/433373 –