注意:
1.tabbar高度不可设置,可通过_tabbar.tabbar.frame设置tabbar的位置
2.tabbar不同页面添加同一个视图后其那面添加的不起作用,只有最后一个才具有所添加的仕途
// AppDelegate.m
// IOStabBar0813
//
// Created by scjy on 15/8/13.
// Copyright (c) 2015年 zyf. All rights reserved.
//
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor=[UIColor whiteColor];
//标签控制器
UITabBarController *_tabBar=[[UITabBarController alloc]init];
//创建用于显示在_tabBar上的视图控制器
UIViewController *oncVC=[[UIViewController alloc]init];
oncVC.view.backgroundColor=[UIColor greenColor];
UIViewController *twoVC=[[UIViewController alloc]init];
twoVC.view.backgroundColor=[UIColor orangeColor];
_tabBar.viewControllers=@[oncVC,twoVC];//三步骤:先创建,再添加,后设置。
_tabBar.tabBar.barTintColor=[UIColor cyanColor];//设置tabbar的颜色
//设置tabbar上的item之前要先将item添加上
UITabBarItem *item1=(UITabBarItem *)[_tabBar.tabBar.items objectAtIndex:0];
[item1 setTitle:@"首页"];
UITabBarItem *item2=(UITabBarItem *)[_tabBar.tabBar.items objectAtIndex:1];
[item2 setTitle:@"设置"];
_tabBar.selectedIndex=1;//默认显示位置
self.window.rootViewController=_tabBar;
[self.window makeKeyAndVisible];
return YES;
}