UITabBarController — 标签视图控制器

UITabBarController 分为三层结构:

(1).tab bar

(2.)Custom Content

(3.). Tab bar controller View

UITabBarController 有下面重要属性:

(1).viewControls 显示的视图控制器

(2).tabBar 标签栏

(3).delegate 代理

(4).selectedindex 选中某个tabBarItme

UITabBar

(1).tabBar是UITabBar对象,包括多个UIBarItem, 每个tabBarItem相应一个ViewController ,tabBar的高度是49

(2).当tabBarItem超过5个时,系统会自己主动添加一个很多其它button,点击很多其它button,没有在底部出现的那些button会议列表形式显示出来

UITabBar 的属性

(1).tintColor

(2).barTintColor

(3).图像设置

tabBarItem能够设置title . image . badgeValue

能够用系统的样式创建tabBarItem

1.创建一个视图控制器对象

代码:

FirstViewController *firstVC=[[FirstViewController alloc] init];

2.创建第一个naVC

代码:

UINavigationController *firstNaVC=[[UINavigationController alloc] initWithRootViewController:firstVC];

3.创建tabbar上的button及其内容(这样的方法是系统方法)

代码:

firstVC.tabBarItem =[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:1000] autorelease];
(1). button上加入”+99”的符号
firstVC.tabBarItem.badgeValue =@"+99";
(2).用自己定义的方法创建:
SecondViewController *secondVC=[[SecondViewController alloc] init];
UINavigationController *secondNaVC=[[UINavigationController alloc] initWithRootViewController:secondVC];
secondVC.tabBarItem =[[[UITabBarItem alloc] initWithTitle:@"朋友圈" image:[UIImage imageNamed:@"缩放.png"] selectedImage:[UIImage imageNamed:@"加号.png"]] autorelease];
(3). 创建第三个(第三种创建方法)
ThirdViewController *thirdVC=[[ThirdViewController alloc] init];
UINavigationController *thirdNaVC=[[UINavigationController alloc] initWithRootViewController:thirdVC];
thirdNaVC.tabBarItem=[[[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed:@"加号.png"] tag:1001] autorelease];

4.button创建好,然后创建一个UITabBarController让全部的button显示出来

代码:

UITabBarController *tabVC=[[UITabBarController alloc] init];

5.tabbarController 通过一个数组来管理全部要显示出来的naVC

代码:

 tabVC.viewControllers =@[firstNaVC,secondNaVC,thirdNaVC,fourNaVC,fiveNaVC,sixNaVC];
self.window.rootViewController =tabVC;

6.对tabbar进行外观设置(取消透明度)

代码:

tabVC.tabBar.translucent =NO;

7.背景颜色

代码:

tabVC.tabBar.barTiniColor =[UIColormagentaColor];

8.点击之后的选中颜色

代码:

 tabVC.tabBar.tintColor=[UIColor blackColor];

9.设置代理人

代码:

tabVC.delegate=self;

10.刚開始停留的页面下标

代码:

tabVC.selectedIndex =2;

11.方法:

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
设置badageValue nil 去掉全部
viewController.tabBarItem.badgeValue=nil;
// 或者(效果稍微不同)
@“” 还剩一个小圆点
// viewController.tabBarItem.badgeValue=@""' }

12.在第一个视图中创建一个TableView

tableView的高度要 减掉tabBar的高度49 和navigationBar的高度64

13.在tableview的第二个协议中的if(!cell)cell创建中,加入一个长按手势和button

代码:

if (!cell) {
cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
//在这里创建长按手势和一个button,也是为了避免反复创建,在反复使用cell的同一时候,也同一时候使用了长安手势和buttonbutton
UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
[cell addGestureRecognizer:longPress];
[longPress release];
UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];
button.frame =CGRectMake(200, 20, 100, 30);
[button setTitle:@"点击" forState:UIControlStateNormal];
[cell addSubview:button]; }

14.在长按手势的方法中能够进行下面操作:

代码:

-(void)click:(UILongPressGestureRecognizer *)longPress{
NSLog(@"111");
// 通过手势,找到手势加入的cell
UITableViewCell *cell = (UITableViewCell *)longPress.view;
// 创建一个快捷菜单
UIMenuController *menu =[UIMenuController sharedMenuController];
// 给这个快捷菜单进行定位
[menu setTargetRect:cell.frame inView:cell.superview];
// 让菜单能够显示出来
[menu setMenuVisible:YES animated:YES];
// 假设想使用自己定义的功能
UIMenuItem *flag =[[UIMenuItem alloc] initWithTitle:@"測试" action:@selector(flag)];
// 把这个button放到快捷菜单上
[menu setMenuItems:@[flag]];
// button假设不实现,不管系统还是自己定义,假设不实现相应的方法,不会加入到快捷菜单上 }

15.快捷菜单捆绑了一个方法,这种方法必须实现,假设不实现,快捷菜单没有办法显示

代码:

-(BOOL)canBecomeFirstResponder{
return YES;
}

16.下面系统给定的显示快捷菜单

-(void)delete:(id)sender{
NSLog(@"删除");
}
-(void)copy:(id)sender{
NSLog(@"复制");
} -(void)select:(id)sender{
NSLog(@"选择");
}

17. 也能够加入自己定义

代码:

-(void)flag{
NSLog(@"111");
}

UITabBarController — 标签视图控制器的更多相关文章

  1. UITabBarController ---- 标签视图控制器

    直接上代码: // // AppDelegate.m // // #import "AppDelegate.h" #import "RootViewController. ...

  2. 自定义UITabBarController标签视图控制器

    首先创建一个类,继承自UItabBarController 然后在.m文件中: 这里我有两个宏定义: #define WIDTH (myView.frame.size.width / 4) //我在写 ...

  3. 标签视图控制器UITabBarController

    标签视图控制器 UITabBarController FirstViewController*first = [[FirstViewController alloc] init]; //创建一个UIT ...

  4. [Xcode 实际操作]三、视图控制器-(2)UITabBarController选项卡(标签)视图控制器

    目录:[Swift]Xcode实际操作 本文将为你演示,选项卡视图控制器的创建和使用. 在项目文件夹[DemoApp]上点击鼠标右键,弹出右键菜单. [New File]->[Cocoa Tou ...

  5. iOS学习22之视图控制器

    1.自定义视图 1> 概述   定义视图:系统标准UI之外,自己组合而出的新的视图. 定义视图的优点: iOS提供了很多UI组件,借助它们我们可以实现不同的功能.尽管如此,实际开发中,我们还需要 ...

  6. 集合视图控制器(CollectionViewController) 、 标签控制器(TabBarController) 、 高级控件介绍

    1 创建集合视图,设置相关属性以满足要求 1.1 问题 集合视图控制器UIConllectionViewController是一个展示大量数据的控制器,系统默认管理着一个集合视图UICollectio ...

  7. Swift - 标签条(UITabBar)标签页控制器(UITabBarController)用法

    App底部的tab标签页可以方便的把功能模块划分清楚,只需点击相应的标签页就可以展示完全独立的视图页面,同时各标签页间的视图也可以进行数据交换.   TabBarItem系统自带图标样式(System ...

  8. 【iOS开发-30】UITabBarController的几种代理方法以及结合NSUserDefaults还原上次退出时被选中视图控制器和视图控制器的顺序

    一.UITabBarController的几种代理方法 在AppDelegate.h中加入一个协议<UITabBarControllerDelegate>.然后再AppDelegate.m ...

  9. 和iPhone有关的视图控制器:UIViewController、UITabBarController、UINavigationController及其混合用法

    iPhone中的view视图是应用程序对于数据最直观.最直接的呈现方式,如下是我在学习了iPhone中的视图控制器以及由其衍生的特殊子类的总结,希望对那些初学者有所帮助: UIViewControll ...

随机推荐

  1. 机器学习之路: python nltk 文本特征提取

    git: https://github.com/linyi0604/MachineLearning 分别使用词袋法和nltk自然预言处理包提供的文本特征提取 from sklearn.feature_ ...

  2. 选择排序之Java实现

    选择排序之Java实现 一.方法一 package cn.com.zfc.lesson21.sort; /** * * @title SelectSort * @describe 选择排序 * @au ...

  3. 让screen帮助你协同工作

    Screen是系统管理员手中的一件利器,下面我把它介绍给你,相信你会和我一样,认可这个非常棒的软件 一,什么情况下会用到screen?   比如说,我们在运行一个非常费时间的程序,注意:可能我们是在通 ...

  4. Codeforces Round #248 (Div. 1) A. Ryouko's Memory Note 水题

    A. Ryouko's Memory Note 题目连接: http://www.codeforces.com/contest/434/problem/A Description Ryouko is ...

  5. offsetLeft && left

    /* function getCss(obj,attr){ return window.getComputedStyle ? window.getComputedStyle(obj,null)[att ...

  6. vc 6.0 远程调试

    http://blog.sina.com.cn/s/blog_45eaa01a01014eb5.html

  7. 再次理解多线程线程安全问题(理解java内存模型后)

    1.多线程访问的共享资源存在线程安全问题, 无外乎访问两种共享资源. 1)多线程访问方法区数据.存在线程安全问题,通过加锁 2)多线程访问实例变量:被访问对象是单例时存在线程安全,被访问对象是多例时, ...

  8. Shell下的通配符、特殊符号和文件描写叙述符

    一:通配符 * 代表『 0 个到无穷多个』随意字符 演示样例:找出 /etc/ 底下以 cron 为开头的文件名称的文件 [root@instructor Desktop]# ls /etc/cron ...

  9. appium+python自动化59-appium命令行参数

    Appium服务器参数 许多Appium 1.5服务器参数已被弃用,以支持--default-capabilities标志. 用法: node . [flags] help 1.cmd端口输入,app ...

  10. MySQL中的模糊查询和通配符转义

    MySQL中实现模糊查询有2种方式:一是用LIKE/NOT LIKE,二是用REGEXP/NOT REGEXP(或RLIKE/NOT RLIKE,它们是同义词). 第一种是标准的SQL模式匹配.它有2 ...