2016-09-06 1 views
3

Ich bin vor kurzem von Swift 2 zu Swift 3 migriert und ich bin auf einem Teil stecken. In meinem AppDelegate würde ich die Standardeinstellungen für die UINavigationBar wie unten codiert einrichten. Die Herausforderung, die ich habe, ist, dass das setBackgroundImage in Swift 3 nicht mehr erkannt wird und ich keine Alternative finden kann.Swift 3: Wie installiere ich UINavigationBar setBackgroundImage in AppDelegate

Hat jemand das gleiche Problem gehabt und konnte es lösen?

let turquoiseBackgroundImage:UIImage = UIImage(named: "navigationBarTurqoise")! 


    **// TODO Below is not working with Swift 3 
    UINavigationBar.appearance().setBackgroundImage(turquoiseBackgroundImage, forBarPosition: .Default)** 


    // Set up Back button to be white in Navigation bar 
    UINavigationBar.appearance().barStyle = UIBarStyle.default 
    UINavigationBar.appearance().tintColor = UIColor.white 

    // Font Name and Size of Title in Navigation Bar 
    if let font = UIFont(name: "TitilliumWeb-Light", size: 20) { 
     UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName : font, NSForegroundColorAttributeName : UIColor.white] 
    } 

    // Remove hairline between navigation bar and anything below such as search bar 
    UINavigationBar.appearance().shadowImage = UIImage() 

    // Set up status bar (battery, time, etc.) to white 
    UIApplication.shared.statusBarStyle = .lightContent 
+0

Swift Erklärung 'func setBackgroundImage (_ Bild: UIImage ?, für Zustand: UIControlState)' https://developer.apple.com/reference/uikit/uibutton/1624016-setbackgroundgroundimage, also versuche 'setBackgroundImage (türkisBackgroundImage, für: .default) *' –

+0

** Tipp: ** Lass das nächste Mal einfach Xcode automatisch für dich vervollständigen. –

+0

Ja, ich habe versucht, die automatische Vervollständigung, aber es gibt keine setBackgroundImage-Funktion überhaupt unter UINavigationBar.Arbeit() .. Es gibt eine SetBackgroundImage-Funktion direkt unter UINavigationBar, aber es dauert eine UINavigationBar als Argument .. Macht keinen Sinn? UINavigationBar.setBackgroundImage (<# T ## UINavigationBar #>) –

Antwort

5
UINavigationBar.appearance().setBackgroundImage(turquoiseBackgroundImage, forBarPosition: .Default) 

Rewrite-Code wie dieser

UINavigationBar.appearance().setBackgroundImage(turquoiseBackgroundImage, for: .default) 
Verwandte Themen