iOS中 UITabBarController中自定义UITabBar
来源:互联网 发布:淘宝的全民抢拍 编辑:程序博客网 时间:2024/05/13 17:56
1.创建多个视图控制器,放如UITabBarController中
AViewController *aa = [[AViewController alloc] init]; UINavigationController* ayNav = [[UINavigationController alloc]initWithRootViewController:aa]; BViewController *bb = [[BViewController alloc] init]; UINavigationController* bNav = [[UINavigationController alloc]initWithRootViewController:bb]; CViewController *cc = [[CViewController alloc] init]; UINavigationController* cNav = [[UINavigationController alloc]initWithRootViewController:cc]; DViewController *dd = [[DViewController alloc] init]; UINavigationController* dNav = [[UINavigationController alloc]initWithRootViewController:dd]; 2.初始化tabbar UITabBarController *tabBarController = [[UITabBarController alloc]init]; tabBarController.delegate=self; tabBarController.viewControllers=[[NSArray alloc]initWithObjects:ayNav,bNav,cNav,dNav,nil];
3.获取到tabBarController中的tabBar,在从tabBar中获取到每个items
UITabBar *tabBar = tabBarController.tabBar; UITabBarItem *aTabBarItem = [tabBar.items objectAtIndex:0]; UITabBarItem *bTabBarItem = [tabBar.items objectAtIndex:1];UITabBarItem *cTabBarItem = [tabBar.items objectAtIndex:2];UITabBarItem *dTabBarItem = [tabBar.items objectAtIndex:3];
4. 设置tabBar中items的标题
aTabBarItem.title = @"小韩哥";bTabBarItem.title = @"iOS编程";cTabBarItem.title = @"ios开发";dTabBarItem.title = @"苹果系统";
5.设置tabBar中items的图片
[aTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"aa_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"1.png"]];[bTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"bb_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"2.png"]];[cTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"cc_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"3.png"]];[dTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"dd_selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"4.png"]];
6.设置tabBar的背景图片
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar1.png"]; [[UITabBar appearance] setBackgroundImage:[tabBarBackground resizableImageWithCapInsets:UIEdgeInsetsZero]]; [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor grayColor], UITextAttributeTextColor, nil nil] forState:UIControlStateNormal]; UIColor *titleHighlightedColor = [UIColor colorWithRed:153/255.0 green:192/255.0 blue:48/255.0 alpha:1.0]; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: titleHighlightedColor, UITextAttributeTextColor, nil nil] forState:UIControlStateHighlighted];
8.将tabBarController加入window中
self.window.rootViewController = tabBarController;[self.window makeKeyAndVisible];
2 0
- iOS中 UITabBarController中自定义UITabBar
- UITabBarController中自定义UITabBar
- UITabBarController中自定义UITabBar
- UITabBarController中自定义UITabBar方法2
- iOS UITabBarController 的 UITabBar 自定义
- 自定义UITabbarController及向UITabBar中添加自定义按钮
- iOS 自定义UITabBarController以及UITabBar的分析
- Swift中如何通过KVC将自定义的UITabbar设置为UITabbarController的tabbar
- 自定义实现UITabBarController和UITabBar
- 自定义UITabBarController、UITabBar和UIButton
- 自定义UITabBarController以及UITabBar的分析
- UItabbarController自定义 常用架构 UITabBar UITabBaritem
- UITabBarController(二)自定义UITabBar方式一
- UITabBarController(三)自定义UITabBar方式二
- UITabBarController、UITabBar
- iOS中UITabbarController的用法
- iOS中UITabBarController的剖析
- (转)IOS自定义UITabBar
- Android Intent的两种用法
- android 2048
- 返回函数局部变量的指针和引用
- c/c++标准预定义宏
- Android手机如何录制屏幕及转GIF
- iOS中 UITabBarController中自定义UITabBar
- 2015移动开发大会观后感与企业应用机遇-2015年11月江西IDC排行榜与发展报告
- Android视频录制命令screenrecord
- 【鸟哥的linux私房菜-学习笔记】软件安装: RPM, SRPM 与 YUM 功能
- JS科学计算器
- linux内核命令行解析
- 惠而浦借势互联网+,开启“中国制造2025”
- CF--A. Tricky Sum
- 【VS开发】CString 转为 char *方法大全