Utku Dalmaz
Utku Dalmaz

Reputation: 10192

Using navigation bar on tab bar controller

I am new in xcode. I use xcode 7.

I am trying to add a navigation bar on tab bar controller.

enter image description here

in that screenshot, i selected top translucent bar black but it doesn't appear when i run the project

My main purpose is to show a top bar and add an image (logo) on it.

How can i achieve this ?

Upvotes: 6

Views: 10070

Answers (3)

NixSolutionsMobile
NixSolutionsMobile

Reputation: 191

You shoul’d manually add navigation bar into your project and set it up manually. Or better is to add Navigation controller

Upvotes: 0

William Kinaan
William Kinaan

Reputation: 28819

To add navigation controller:

select your view controller, then from 'Editor' -> Embed in -> Navigation Controller

To add image to your navigation bar, do this in your view did load :

let logo = UIImage(named: "yourimage.png")
let imageView = UIImageView(image:logo)
self.navigationItem.titleView = imageView

To change the image size, you would need to change the imageView size as the folowoing

        let imageView = UIImageView(frame: CGRectMake(100, 150, 150, 150)); // set as you want
    imageView.image = logo;
self.navigationItem.titleView = imageView

Upvotes: 2

Jay Bhalani
Jay Bhalani

Reputation: 4171

Your format is not correct. please add Navigation Controller in your tab controller.

Select your ViewController and Click Editor > Embed In > Navigation Controller

like this :

enter image description here

Add navigation controller like this :

enter image description here

I hope its work for you.

Add image to your navigation bar :

var image = UIImage(named: "abc.jpg") as UIImage
self.navigationController.navigationBar.setBackgroundImage(image, 
                                                   forBarMetrics: .Default)

Upvotes: 15

Related Questions