Custom Navigation Bar

Did you know that you can customize a Navigation Bar? Let’s do it. It’s very easy.

Create a new project. Go to storyboard. Click on the ViewController. Go to “Editor -> Embed in -> Navigation Controller”. So, a Navigation Bar was created. Now add two bar buttons.

Add an image to your Assets.xcassets folder that you would like to display in the Navigation Bar.

Let’s code now. Go to ViewController.swift.

Write a new function override func viewDidAppear(animated: Bool).

Then add this code to the function:

Now let’s go through code line by line.

  1. Initializing the Navigation Bar.
  2. Defining the style of our Navigation Bar.
  3. Setting the color of our bar buttons.
  4. Initializing the imageView, so we have a place to display our image.
  5. Creating an image and setting it to our imageView.
  6. Adding imageView to our Navigation Bar.
  7. Done. Run the project

Your Navigation Bar was customized. Super easy.


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.