0
votes

I am using background image for the navigation bar. And it is crashing my app while presenting a view controller. I am also having the background image for all the view controller's view. I am using implementing like this

func setNavigationAppearance(tintColor : UIColor, barTintColor : UIColor?) {
    let navigationBarAppearace = appDelegateObj.navigationController!.navigationBar

    navigationBarAppearace.tintColor = tintColor
    navigationBarAppearace.barTintColor = barTintColor
    navigationBarAppearace.translucent = false

    //navigationBarAppearace.
    //Settign the Custome Font and TextColor

    if let font = UIFont(name: FontCustom.Regular, size: 17) {
        UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: font ,NSForegroundColorAttributeName : tintColor]
    }
}

I call this method with this image let navigationColor : UIColor = UIColor(patternImage: UIImage(named: AppImagesName.PatternRed)!)

And I am getting these crash logs.

terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation

I Googled about this, all are saying that remove the background image or this is iOS bug.

So please let me know what could be the solution.

1
Where is the code for setting background image for navigation bar?KSR
@SathiReddy I have updated the question. Please have a look.Gopal Devra
I am working on your issue...KSR
I added the code ..please check.. Now i am uploading the sample project to GitHub and give link to test..KSR

1 Answers

1
votes

To set background image to NavigationBar, use the following code:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        if let myImage = UIImage(named: "navBarImage.jpg"){
            UINavigationBar.appearance().setBackgroundImage(myImage, for: .default)
        }


        return true
    }

A sample screenshot:

enter image description here

To test sample, please check my GitHub link:

https://github.com/k-sathireddy/NavigationBarBackgroundImageSample