Reputation: 10192
I am new in xcode. I use xcode 7.
I am trying to add a navigation bar on tab bar controller.
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
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
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
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 :
Add navigation controller like this :
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