将顶部栏添加到所有视图可见的iOS应用程序

时间:2014-12-18 18:46:29

标签: ios objective-c uiview

在标签栏iOS应用程序中添加顶部栏(视图)的最佳方法是什么,它总是保留在所有视图的顶部,无论选择哪个选项卡如下图所示?

enter image description here

2 个答案:

答案 0 :(得分:1)

我会使用UIViewControllerContainment。看看

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

我设置它的方式是有一个UIViewController,它有两个ContainerViews。一个ContainerView将包含UITabBarController,另一个将具有顶部栏的UIViewController。

这是我在UIStoryboard中所做的 enter image description here

答案 1 :(得分:0)

子类UIViewController并使用以下内容更改viewDidLoad:方法中的标题和标题视图:

- (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;
  }
}

然后在选项卡中的所有视图控制器上使用此子类。