Swift 中的 Youtube 风格导航栏
Youtube Style Navbar in Swift
我想知道如何使用 Swift.
获得比导航栏颜色更深的状态栏颜色,就像 youtube 在其新应用(material 设计)中所做的那样
编辑
我想要新应用设计的设计。不是旧的。这与仅更改状态栏文本颜色无关。所以哪个旋钮暗示它是重复的没有理解能力
所以我发现我必须在导航栏上添加一个子视图,然后添加一个较深的红色阴影作为视图的背景。如果您的导航栏颜色在整个应用程序中相同,则可以在 UINavigationClass
中使用,也可以在 viewcontroller 中添加以使其不同。
你可以像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.
获得比导航栏颜色更深的状态栏颜色,就像 youtube 在其新应用(material 设计)中所做的那样编辑
我想要新应用设计的设计。不是旧的。这与仅更改状态栏文本颜色无关。所以哪个旋钮暗示它是重复的没有理解能力
所以我发现我必须在导航栏上添加一个子视图,然后添加一个较深的红色阴影作为视图的背景。如果您的导航栏颜色在整个应用程序中相同,则可以在 UINavigationClass
中使用,也可以在 viewcontroller 中添加以使其不同。
你可以像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))
}
}
结果