0

I am trying to create my own Navigation Controller class so that I can use wherever I want with the same customized properties. To achieve that I tried to implement new navigation controller class that inherits from UINavigationController. With customized code I was able to change the background image but I could not create custom bar button item.

Below you can see my custom navigation controller.

//Some navigation properties to be customized
        let navBar = self.navigationBar
        let navItem = self.navigationItem

        //Background image creation
        let image = UIImage(named: "usttab.jpg")

        //Assigning background image
        navBar.setBackgroundImage(image, forBarMetrics: .Default)

        //Customizing navigation item
        navItem.backBarButtonItem = UIBarButtonItem(title: "Geri", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)

Short of the long story my back button's title does not change.

With assigning back bar button item property in the view controllers separately but it does not make sense to copy paste same code to every view controller. Thus, I want to create my own navigation controller class to use anywhere I want.

Please let me know if you need further information about my code.

Thanks,

3
  • You want the same properties across subclasses of UIViewController. Why not have a base subclass of UIViewController? Commented Mar 10, 2016 at 21:18
  • Sorry to see your answer late. What you suggested does really makes sense @beyowulf , the first thing I tried was to customizing navigation controller by implementing it. Creating a base class of view controller and using it as a base class makes really sense. I will try it. Commented Mar 10, 2016 at 22:06
  • @beyowulf Can you write your comment as an answer so that it can be easily seen when any other person would like to search the same problem and also so that I can accept. Thanks again Commented Mar 10, 2016 at 22:08

1 Answer 1

2

If you are setting the same properties across multiple subclasses of UIViewController, you can create a base subclass of UIViewController and subclass that base subclass. This will allow those properties to be shared and allows you to avoid repeating code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.