设为首页 加入收藏

TOP

UI整理-----part9--标签控制器(tabBarController)(二)
2017-10-11 15:00:54 】 浏览:8497
Tags:整理 -----part9-- 标签 控制器 tabBarController
creatNewControllerWithSelectImageName:SelectImageName]; } - (void)creatNewControllerWithSelectImageName:(NSString *)selectImageName { //创建的control的宽度 CGFloat controlWidth = [UIScreen mainScreen].bounds.size.width/self.viewControllers.count; //初始化选中的control的背景视图 _selectImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,controlWidth, 49)]; _selectImage.image = [UIImage imageNamed:selectImageName]; [_newTabBar addSubview:_selectImage]; //首先通过for循环了解产生controller的数量 for (int i = 0; i < self.viewControllers.count; i ++) { //自定义控件 UIControl *newControl = [[UIControl alloc] initWithFrame:CGRectMake(i * controlWidth, 0, controlWidth, 45)]; //将自定义的tabBarButton 添加到 自定义的tabBar上 [_newTabBar addSubview:newControl]; //添加点击效果 [newControl addTarget:self action:@selector(controlAction:) forControlEvents:UIControlEventTouchUpInside]; //通过设置tag方便传值 newControl.tag = 1000 + i; //得到当前的控制器 UIViewController *viewC = [self.viewControllers objectAtIndex:i]; //拿到之前的图片和信息 UIImageView *imageView = [[UIImageView alloc] init]; imageView.image = viewC.tabBarItem.image; UILabel *label = [[UILabel alloc] init]; label.text = viewC.tabBarItem.title; } } // - (void)controlAction:(UIControl *)control { self.selectedIndex = control.tag - 1000; //通过获得的tag值进行切换ViewController //移动动画效果的实现 [UIView animateWithDuration:.4 animations:^{ _selectImage.center = control.center; }]; } /* 细节很重要 (1)用tabBar的selectedIndex属性,可以让自己创建的按钮关联到ViewController (2)取消系统的高亮:可以定义一个按钮,覆写里面的setHighlied方法,什么也不做就行了 (3)关于几个按钮只选中一个的方法:设置一个属性,记录上一个选中的按钮,点击当前按钮,把上一个按钮设置为未选中,并把当前的按钮设置为选中,最后把当前按钮赋值给上一个按钮 */

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇UI整理-----part9--标签控制器(t.. 下一篇MacOS下Express安装过程中遇到的..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目