Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restore default navigation bar appearance

I'm making an iOS app for iPhone, and I'm using a navigation controller. At some point during the navigation, I'm adding a UISegmentedControl to a view controller, just under the navigation bar from the navigation controller. I'm inserting new background and shadow images in the navigation bar, to make the UISegmentedControl appear as part of the navigation bar. I do it like this:

    // nav bar color image
    let rect = CGRectMake(0, 0, view.frame.width, 0.5)          // Used in navBar, size dosn't matter
    UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)
    barBackgroundColor.setFill()
    UIRectFill(rect)
    let navBarBackground = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    // setup navbar
    navigationController!.navigationBar.setBackgroundImage(navBarBackground, forBarMetrics: .Default)
    navigationController!.navigationBar.shadowImage = UIImage()
    navigationController!.navigationBar.tintColor = UIColor.blackColor()
    navigationController!.navigationBar.translucent = false

When I navigate away from that given view controller, the navigation bars background is still changed.

How can I restore the navigation bars appearance?

Or...

Is there another way embed the UISegmentedControl into an expanded navigation bar?

Image of navigation bar with custom background and Segmented Control below: Navbar with custom background. plus segment control below

When navigating back, the navigation bar cuntinues to be custom: enter image description here

EDIT:

In a view controller before i change the background images, i try to safe the standart image:

override func viewDidAppear(animated: Bool) {

    if sharedVariables.standartNavBarBackgroundImage == nil {
        let herp = navigationController!.navigationBar.backgroundImageForBarMetrics(.Default)
        sharedVariables.standartNavBarBackgroundImage = herp
        let derp = navigationController!.navigationBar.shadowImage
        sharedVariables.standartNavBarShadowImage = derp
    }
}

Both herp and derp are nil after being set, dispite the navigationbar is visible at this momont. How come?

like image 778
Wiingaard Avatar asked Dec 07 '15 19:12

Wiingaard


People also ask

How do I reset my navigation bar?

Click the Collapse Pane icon in the space between the Navigation Bar and the Main Window. The Navigation Bar is collapsed, and the Main Window is expanded horizontally across the entire screen. 2. To restore the Navigation Bar to its original width, click the Restore Pane icon on the left side of the window.

How do I get rid of the transparent navigation bar?

How to remove opacity or transparency from sticky navigation/menu bar. If you want to remove the opacity or transparency from the sticky navigation bar, just navigate to Theme Options -> General -> Additional CSS and copy/paste this code and save changes.

How do I change the navigation bar on my Iphone?

A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.


1 Answers

You should be able to get the default appearance back just by setting the background image and shadow image to nil.

like image 162
Noah Witherspoon Avatar answered Sep 27 '22 20:09

Noah Witherspoon