我一直在这个问题上已经有一段时间了,无法找到解决我的问题。使用故事板与自定义UITabbarController
我有我试图与图像来定制的TabBar视图控制器,我有然而工作我需要使用代码来显示和INIT使用TabBar的视图控制器的自定义图形。我也有一个问题,显示导航栏在我的标签之一的顶部,我认为是连接到我如何启动标签视图控制器
故事板显示应该有一个导航栏在顶部药物选项卡和该视图通过segue连接到标签栏 您可以看到我试图使用storyboard segues将我的视图控制器链接到标签栏控制器。我在MedicationViewController.m
/
// MedicationViewController.m
// fibromapp
//
// Created by jamie mcallister on 08/09/2013.
// Copyright (c) 2013 Jamie McAllister. All rights reserved.
//
#import "MedicationViewController.h"
#import "TakenViewController.h"
#import "MedsListViewController.h"
#import "MedsAlarmViewController.h"
@interface MedicationViewController()
@end
@implementation MedicationViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
TakenViewController *viewController2 = [[TakenViewController alloc] init];
MedsListViewController *viewController1 = [[MedsListViewController alloc] init];
MedsAlarmViewController *viewController3 = [[MedsAlarmViewController alloc] init];
self.viewControllers = [NSArray arrayWithObjects:viewController1,
viewController2,
viewController3,nil];
UITabBarItem *tab1 = [[UITabBarItem alloc] initWithTitle:@"Medication" image:[UIImage imageNamed:NULL] tag:1];
UITabBarItem *tab2 = [[UITabBarItem alloc] initWithTitle:@"Taken" image:[UIImage imageNamed:NULL] tag:2];
UITabBarItem *tab3 = [[UITabBarItem alloc] initWithTitle:@"Alarms" image:[UIImage imageNamed:NULL] tag:3];
UIImage* sel = [UIImage imageNamed:@"fmtabSel"];
[viewController1 setTabBarItem:tab1];
[viewController2 setTabBarItem:tab2];
[viewController3 setTabBarItem:tab3];
UIImage* tabBarBackground = [UIImage imageNamed:@"fmtab.png"];
UITabBar *tabBar = self.tabBar;
[tabBar setBackgroundImage:tabBarBackground];
[tabBar setSelectionIndicatorImage:sel];
}
return self;
}
- (void)viewDidLoad
{
UITabBar *tabbar = self.tabBar;
NSLog(@"%f %f", tabbar.frame.size.width, tabbar.frame.size.height);//used to find the size of the bar
[super viewDidLoad];
UIImage* tabBarBackground = [UIImage imageNamed:@"fmtab.png"];
UIImage* sel = [UIImage imageNamed:@"fmtabSel"];
UITabBar *tabBar = self.tabBar;
[tabBar setBackgroundImage:tabBarBackground];
[tabBar setSelectionIndicatorImage:sel];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
与此代码我得到的标签,但有在该选项卡的顶部没有导航栏下面的代码。
任何人可以建议什么我必须这样做,以解决这个问题?
如果您需要任何更多信息随便问,我将它编辑成这个问题的底部。 在此先感谢:)
谢谢你,这代码似乎已经奏效,但它看起来像我的应用程序,现在依靠代码,而不是在一些地区的应用(如导航栏标题)。对我来说有点问题,因为我在故事板的导航栏中有一个按钮,可以将项目添加到列表中 –
正如莱昂纳多说过的,您可以在故事板中执行此操作。我刚刚向你展示了一个移动方向 - 带有导航的tabbar。 – Stas