【问题标题】:Youtube Style Navbar in SwiftSwift 中的 Youtube 风格导航栏
【发布时间】:2016-02-15 18:30:04
【问题描述】:

我想知道如何实现比导航栏颜色更暗的状态栏颜色,就像 youtube 在使用 Swift 的新应用(材料设计)中所做的那样。

编辑

我想要新应用设计的设计。不是旧的。这与仅更改状态栏文本颜色无关。所以哪个旋钮暗示它的复制品没有理解能力

【问题讨论】:

标签: swift user-interface youtube uinavigationcontroller uinavigationbar


【解决方案1】:

所以我发现我必须在导航栏上添加一个子视图,然后添加一个较暗的红色阴影作为视图的背景。如果您的导航栏颜色在整个应用程序中相同,则可以在 UINavigationClass 中使用它,也可以将其添加到视图控制器中以使其不同。

【讨论】:

    【解决方案2】:

    你可以像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))
        }
    }
    

    结果

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-07-08
      • 2018-12-11
      • 1970-01-01
      相关资源
      最近更新 更多