How To Customize The Navigation Bar? An iOS Tutorial
Hey everyone, Hope you all are doing great. In this small and very basic iOS tutorial, I’ll guide you how you can customize your app’s navigation bar. After reading this post, you will be able to change the colours of your navigation bar, add image view as title in navigation bar, how to add bar button items, how to change the colours of bar button items etc. So, let’s get started. 🙂
First of all, as usual, open your Xcode and create a new Single View Application as shown in the image below:
Give some name to your product, add other details like organization name, organization identifier etc. Make sure to choose Swift as the language and hit on Next button.
So now, as we need to customize our navigation bar so first we have to embed our view controller in Navigation Controller. For that, Go to storyboard and select your View Controller. Now from the Xcode menu bar, choose Editor > Embed In > Navigation Controller.
After this your View Controller will look like this:
Now, we will add two bar button items in our navigation bar in both left and right corners. For that, just go to the Object Library, choose Bar button item and give it some name like “Left Item”. Again, add one more bar button item from object library and give it some name like “Right Item”.
Now we also want to add/show some image in the centre of our navigation bar, so for that, first add an image to your assets folder. Just open the Assets Library and drag your chosen image into it.
Now Go to your ViewController.swift file and add viewDidApear() Method. Under this method, add following lines of code. (I’ve commented the use of each line of code for your better understanding in this code snippet. )
Now run your app and you’ll get something like this on your screen.
That’s all for today’s post about customizing the navigation bar of your iOS apps. It was easy and simple to do. I hope you enjoyed.
If you’ve any doubts or need any further help, then do message me in the comments section below and I’ll try to respond you as soon as possible.
Thanks for your time and keep coding.. 👨💻