hariszaman
hariszaman

Reputation: 8432

Add a topbar to iOS application visible to all views

What is the best way to add a topbar(View) in a tabbar iOS application that always remain on top of all the views, irrespective of which tab is selected like the image below?

enter image description here

Upvotes: 0

Views: 821

Answers (2)

Juan de la Torre
Juan de la Torre

Reputation: 1297

Subclass UIViewController and change the title and title view in the viewDidLoad: method with something like this:

- (void)viewDidLoad
{
  [super viewDidLoad];

  if (!self.title || [self.title isEqualToString:@""]) {
      self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo.png"]];
  } else {
      self.navigationItem.title = self.title;
  }
}

Then use this subclass on all the view controllers that you will have in your tabs.

Upvotes: 0

aahrens
aahrens

Reputation: 5590

I would use UIViewControllerContainment. Take a look at

https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html

The way I'd set it up is have a UIViewController that has two ContainerViews. One ContainerView will have the UITabBarController in it and the other would have the UIViewController for the top bar.

Here is what I did in a UIStoryboard enter image description here

Upvotes: 1

Related Questions