6
votes

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 ?

3
have you tried to embed it in a navigation controller?William Kinaan
how to do that, can you please explain ?Utku Dalmaz
check my edited Answer @RULE101Jay Bhalani
@RULE101 select your view controller, then from 'Editor' -> Embed in -> Navigation ControllerWilliam Kinaan
@RULE101 check my answer pleaseWilliam Kinaan

3 Answers

15
votes

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)
2
votes

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
0
votes

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