2017-12-26 6 views
0

-Code setzen:Wie Verlaufsfarbe für statusbar

extension UIApplication { 
    class var statusBarBackgroundColor: UIColor? { 
     get { 
      return (shared.value(forKey: "statusBar") as? UIView)?.backgroundColor 
     } set { 
      (shared.value(forKey: "statusBar") as? UIView)?.backgroundColor = newValue 
     } 
    } 
} 

UIApplication.statusBarBackgroundColor = .blue 

Ich versuche zu setzen Farbverlauf für Statusleiste alone.How Code geändert werden Gradienten colour.any Hilfe eingestellt werden appreciated.THANKS im voraus sein

+0

Haben Sie nur Statusleiste oder statusbar + Navigationsleiste bedeuten? – Hexfire

+0

statusbar nur .. –

Antwort

0

So handhabe ich es.

let gradientLayer = CAGradientLayer() 

    gradientLayer.frame = CGRect(x:0, y:-20, width:375, height:64) 
    let colorTop = UIColor(red: 69/255, green: 90/255, blue: 195/255, alpha: 1.0).cgColor 
    let colorBottom = UIColor(red: 230/255, green: 44/255, blue: 75/255, alpha: 1.0).cgColor 
    gradientLayer.colors = [ colorTop, colorBottom] 
    gradientLayer.locations = [ 0.0, 1.0] 
    gradientLayer.frame = CGRect(x:0, y:-20, width:375, height:self.view.frame.height * 0.06) 

    let window: UIWindow? = UIApplication.shared.keyWindow 
    let view = UIView() 
    view.backgroundColor = UIColor.clear 
    view.translatesAutoresizingMaskIntoConstraints = false 
    view.frame = CGRect(x: 0, y: 0, width: (window?.frame.width)!, height: self.view.frame.height * 0.07) 
    view.layer.addSublayer(gradientLayer) 
    window?.addSubview(view) 

, dass nur die Steigung auf die hinter der Statusleiste Ansicht hinzufügen

+0

da ich Navigationscontroller versteckt Ihre Lösung nicht funktioniert –

+0

Ich habe die Antwort bearbeitet, wie Sie Navigation Controller verstecken –

+0

danke für Ihre Hilfe .. –