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. BeautifulSoup与Xpath解析库总结

    一.BeautifulSoup解析库 1.快速开始 html_doc = """ <html><head><title>The Dor ...

  2. 时间插件datetimepicker

    相关datetimepicker用法查看官网http://eonasdan.github.io/bootstrap-datetimepicker/ {% load staticfiles %} < ...

  3. bzoj 4573: [Zjoi2016]大森林 lct splay

    http://www.lydsy.com/JudgeOnline/problem.php?id=4573 http://blog.csdn.net/lych_cys/article/details/5 ...

  4. kali下利用weeman进行网页钓鱼

    工具下载链接:https://files.cnblogs.com/files/wh4am1/weeman-master.zip 利用wget命令下载zip压缩包 利用unzip命令解压 接着直接cd进 ...

  5. JavaScript操作DOM(动态表格处理)

    <html> <title>动态处理表格数据</title> <head> <script type="text/javascript& ...

  6. Go语言Web框架gwk介绍 (四)

    事件 gwk支持事件系统,但并没有硬编码有哪些事件,而是采用了比较松散的定义方式. 订阅事件有两种方式: 调用On函数或者OnFunc函数 func On(moudle, name string, h ...

  7. [Dynamic Language] Python3.7 源码安装 ModuleNotFoundError: No module named '_ctypes' 解决记录

    Python3.7 源码安装 ModuleNotFoundError: No module named '_ctypes' 解决记录 源码安装时报错 File "/home/abeenser ...

  8. The YubiKey NEO -- Smartcard features

    Smartcard features on the YubiKey NEO YubiKeys are a line of small and low-cost hardware security to ...

  9. [转载] 关于matlab GUI的一点心得

    转载自 落落轻尘 [Fig文件方式,即使用菜单File->New->GUI来设计界面] 首先值得注意的是,在低版本matlab上制作的含GUI的m文件一般不能在高版本的matlab上面运行 ...

  10. C# 中提取表中的某一项数据