Ich versuche, meine UINavigationBar
in UINavigationController
transparent zu machen. Ich habe eine Unterklasse von UINavigationController
erstellt und eine Szene in meiner Storyboard-Datei gemocht. Hier ist ein Stück meiner Unterklasse:Transparente UINavigationBar in Swift
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let size = self.navigationBar.frame.size
self.navigationBar.setBackgroundImage(imageWithColor(UIColor.blackColor(), size: size, alpha: 0.2), forBarMetrics: UIBarMetrics.Default)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func imageWithColor(color: UIColor, size: CGSize, alpha: CGFloat) -> UIImage {
UIGraphicsBeginImageContext(size)
let currentContext = UIGraphicsGetCurrentContext()
let fillRect = CGRectMake(0, 0, size.width, size.height)
CGContextSetFillColorWithColor(currentContext, color.CGColor)
CGContextSetAlpha(currentContext, alpha)
CGContextFillRect(currentContext, fillRect)
let retval: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return retval
}
Wenn ich meine Anwendung eines Lauf einer Navigationsleiste transparent, aber Statusleiste ist nur schwarz.
Zum Beispiel, wenn ich so etwas auf UITabBar
- es funktioniert.
Jetzt kann ich meine Navigationsleiste nicht sehen. Es funktioniert nicht –
Was meinst du mit transparent dann? @NikitaZernov Transparent = klare Farbe. Sie können nur Titel und Schaltfläche sehen. –
Er möchte seine Statusleiste transparent machen. –