简体   繁体   中英

Swift 3: How to set up UINavigationBar setBackgroundImage in AppDelegate

I recently migrated from Swift 2 to Swift 3 and I'm stuck on one part. In my AppDelegate, I'd set up the default settings for the UINavigationBar as coded below. The challenge I'm having is that the setBackgroundImage is no longer recognized in Swift 3 and I can't find an alternative.

Has anyone had the same issue happen and been able to resolve it?

    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
UINavigationBar.appearance().setBackgroundImage(turquoiseBackgroundImage, forBarPosition: .Default)

像这样重写代码

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM