Replacing UINavigationControllers NavigationBar wi

2019-03-05 08:44发布

问题:

I am developing app that has multiple skins and I have a dilema on how to implement this.

One of the solutions would be to have separate nib files for every skin, and load it depending on wich skin is currently selected. Problem with this is that I can't edit navigation bar of navigation controller (wich my app uses), and I have to change it's background image and back button image etc.. I came up with an idea to hide this navigation bar on every screen and replace it with custom UIView in Interface Builder wich will act as navigation bar and custom back button with IBAction for popping current View Controller, so that user won't see any difference.

Is this approach acceptable and if I make it this way, will I have problems with rejection in App Store?

回答1:

If you choose to hide & replace the UINavigationBar with your own UIView it's no problem as far as Apple goes.

However, I can tell you that you will have to spend some time trying to replicate some visual effects that come naturally with UINavigationBar.

For example, when you push/pop a new controller, you will see that the navigation bar title will slide & fade beautifully. The same applies for left and right bar items.

Personally I would not completely hide the UINavigationBar, but customize it. In the end it all depends on what you want, but by default the UINavigationBar is pretty customizable.

You can add your own buttons or even entire UIViews as left and right bar items. Also, you can add your own UIView as the title (with your own label, custom font or whatever) or change the background.

EDIT:

To easily customize the looks in your entire application, you can subclass UINavigationController and create your own CustomUINavigationController. Then, in viewDidLoad method you can change whatever you want to the navigation bar and this will be accessible in the entire application.



回答2:

No way, what you are doing is perfect. This will work & no way it will get rejected from app store (just based on this approach). I too have explored several ways to provide skins & what you wrote seemed to be the least hassle-some. Plus its way more easier to create UI elements in Interface Builder hence the separate nib files for different skins.

I am saying this so confidently 'coz I have done the same thing & app store approved.

Best of luck.