获取TabbarController中点击item事件
2016-03-06 00:00
134 查看
摘要: 获取TabbarController中点击item事件
获取TabbarController中点击item事件的方法
只需要在TabbarController里实现这个代理方法
然后你可以通过字符串title的判断
就可以知道将要显示的是哪个控制器
tabbar属性设置
学自这个网址的回答:
获取TabbarController中点击item事件的方法
只需要在TabbarController里实现这个代理方法
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { NSLog(@"%@",item.title); }
然后你可以通过字符串title的判断
就可以知道将要显示的是哪个控制器
tabbar属性设置
/// 设置 tabbar - (void)abountTabbar { //新闻 XNNewsController *news = [XNNewsController newsControllerLoadXib]; [self addChildViewController:news imageName:@"tabbar_home" title:@"新闻"]; //本地 XNHereController *ereCtrl = [XNHereController hereControllerLoadXib]; [self addChildViewController:ereCtrl imageName:@"tabbar_message_center" title:@"本地"]; // 爆料 XNExplodeDataController *explodeCtrl = [XNExplodeDataController explodeDataControllerLoadXib]; [self addChildViewController:explodeCtrl imageName:@"tabbar_discover" title:@"爆料"]; // 我的 XNMyViewController *myCtrl = [XNMyViewController myViewControllerLoadXib]; [self addChildViewController:myCtrl imageName:@"tabbar_profile" title:@"我的"]; } // 添加子控制器,并设置标题与图片 - (void)addChildViewController:(UIViewController *)childCtrl imageName:(NSString *)imageName title:(NSString *)title{ childCtrl.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; childCtrl.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; //设置标题 childCtrl.tabBarItem.title = title; //指定一下属性 NSMutableDictionary *dic = [NSMutableDictionary dictionary]; // 指定选中状态下文字颜色 dic[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.835 green:0.090 blue:0.125 alpha:1.000]; [childCtrl.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected]; [self addChildViewController:childCtrl]; }
学自这个网址的回答:
相关文章推荐
- 动画效果
- scrollView中的label横条效果Demo
- Linux访问光驱内容(加载光驱\访问cdrom\加载cdrom\创建加载点)
- Linux 每日一颗 fdisk
- css background 的一些新属性
- 锚点定位
- 导致js内存泄漏的几种场景
- JSONP 的实现原理
- Swift构造函数
- Windows服务器负载均衡
- 一个实用的JS自定义函数addLoadEvent()
- 关于linux下的缓存机制
- vb.net中image转string
- nginx lua redis 访问频率限制(转)
- Python学习之路--面向对象
- 2016第9周六
- 浮点数据与4个单字节的转换
- [置顶] PHP语言代码漏洞审计技巧笔记分享
- DICOM:dcm4chee开源框架编译相关问题总结
- nginx+lua+redis构建高并发应用(转)