UI UITabBarController
2015-04-28 19:34
260 查看
<span style="font-size:18px;">AppDelegate.m - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. UITabBarController *tabVC=[[UITabBarController alloc]init]; //凡是实现UIAppearance协议的类,都可以实现类似一键换肤的功能。设置所有导航条的颜色 [[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]]; //首页 HomeViewController *homeVC=[[HomeViewController alloc]init]; UINavigationController *homeNC=[[UINavigationController alloc]initWithRootViewController:homeVC]; //搜索 SearchViewController *searchVC=[[SearchViewController alloc]init]; UINavigationController *searchNC=[[UINavigationController alloc]initWithRootViewController:searchVC]; //收藏 FavorViewController *favorVC=[[FavorViewController alloc]init]; UINavigationController *favorNC=[[UINavigationController alloc]initWithRootViewController:favorVC]; FourViewController *fourVC=[[FourViewController alloc]init]; UINavigationController *fourNC=[[UINavigationController alloc]initWithRootViewController:fourVC]; FiveViewController *fiveVC=[[FiveViewController alloc]init]; UINavigationController *fiveNC=[[UINavigationController alloc]initWithRootViewController:fiveVC]; SixViewController *sixVC=[[SixViewController alloc]init]; UINavigationController *sixNC=[[UINavigationController alloc]initWithRootViewController:sixVC]; //将试图装入tabVC tabVC.viewControllers=@[homeNC,searchNC,favorNC,fourNC,fiveNC,sixNC]; //设置tabBar上字体的颜色 tabVC.tabBar.tintColor=[UIColor redColor]; //设置tabBar的颜色 tabVC.tabBar.barTintColor=[UIColor blueColor]; //设置背景图片 [tabVC.tabBar setBackgroundImage:[UIImage imageNamed:@"1.png"]]; //把边缘以外的内容 tabVC.tabBar.clipsToBounds=YES; //选中某一个页面 tabVC.selectedIndex=1; //设置代理 tabVC.delegate=self; self.window.rootViewController=tabVC; [tabVC release]; [homeVC release]; [homeNC release]; [searchVC release]; [searchNC release]; [favorVC release]; [favorNC release]; [fourVC release]; [fourNC release]; [fiveNC release]; [fiveVC release]; [sixNC release]; [sixVC release]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { NSLog(@"%d",tabBarController.selectedIndex); } </span>
<pre name="code" class="objc"><span style="font-size:18px;">HomeViewController.m - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { //设置navigationBar和tabBar上的title //放在viewDidLoad方法中不点击是不加载是不会显示的,所以在初始化方法中写 self.title=@"首页"; UITabBarItem *item=[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:100]; //设置badgeValue(右上角信息数) item.badgeValue=@"1"; self.tabBarItem=item; [item release]; // //图片是镂空的 // UIImage *img=[[UIImage imageNamed:@"2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // UITabBarItem *item=[[UITabBarItem alloc]initWithTitle:@"首页" image:img tag:100]; // self.tabBarItem=item; // [item release]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor=[UIColor yellowColor]; } </span>
相关文章推荐
- IOS--UI--LessonUITabBarController 标签控制器
- iOS之UI--UITabBarController
- 自学iOS开发系列----UI(视图编程入门:UITabBarController)
- UI12_UItabBarViewController
- iOS开发UI高级—14UITabBarController简单介绍
- UI进阶--UITabBarController简单介绍
- UI基础篇-------UITabBarController的使用
- UI: 使用 UITabBarController 显示多视图控制器
- 第一篇、Swift_搭建UITabBarController + 4UINavigationController主框架
- swift-UI控件开发之UITabBarController的创建
- 【学习ios之路:UI系列】UITabBarController , UIToorBar
- UI课程14 标签视图控制器 UITabBarController
- 第07章 UITabBarController & UIPickerView
- UI进阶第七发:UITabBarController生命周期(使用storyoard搭建)
- OC-UICollectionViewController& UITabBarController
- UI基础-UITabBarController标签视图
- 爬爬爬之路:UI(十二) 单例 UITabBarController 高级Block的应用
- UI_UITabBarController
- UI进阶第七发:UITabBarController简单介绍
- UI_UItabBarController