Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar setBackgroundImage in AppDelegate with Swift

I am trying to set a background image to the navigation bar globally in the App Delegate in Swift. I can get it to work on an individual View Controller like this:

var topBar: UINavigationBar!

topBar.setBackgroundImage(UIImage(named: "navbar"), forBarMetrics:
.Default)

But when I try and add the following to the App Delegate, it crashes with an uncaught exception:

UINavigationBar.appearance().setBackgroundImage(UIImage(named:
"navbar"), forBarMetrics: .Default)
like image 554
mrcrowley Avatar asked Dec 31 '25 09:12

mrcrowley


1 Answers

OK, I deleted the navigation bars and added new ones in the storyboard... now it works with just the App Delegate code. It's just Xcode 6/Swift being buggy, I guess.

like image 126
mrcrowley Avatar answered Jan 03 '26 04:01

mrcrowley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!