rmooney
rmooney

Reputation: 6229

Set custom UINavigationBar class from Interface Builder

I would like to have a custom UINavigationController subclass that has a custom UINavigationBar class as its nav bar, but it needs to be something that can be set from a storyboard.

I don't see any other way to set the navigationBarClass on a UINavigationController (even when subclassed) besides the init function that has a navigationBarClass as a parameter, but this will ignore the nib attributes and rootViewController (and crash).

class CustomNavigationController : UINavigationController {
  override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
      //This clearly doesn't work because it will not account for the styling, 
      // attributes, and rootViewController applied from the nib
      super.init(navigationBarClass: CustomNavigationBar, toolbarClass: nil)

  }
}

Is there a way around this? Or can I assume there is no way to use a custom navigation bar class inside a storyboard?

Upvotes: 2

Views: 490

Answers (1)

Sebastian Roth
Sebastian Roth

Reputation: 11537

In IB, open your Navigation Controller, then in the list on the left, select the "Navigation Bar": Navigation Controller element list

In the inspector on the right, change the Custom Class: Navigation Bar Inspector

Upvotes: 2

Related Questions