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之排序与列表

    排序时程序中用得比较多的方法了.在Python中,最简单的排序方法摸过与使用内置的sorted(list)这个函数了,该函数一一个列表作为参数返回一个新的列表,只不过是把旧列表中的元素排过序了.原列表 ...

  2. django组件之contenttype(一)

    方式1:适用于1张表和另一张表要关联的时候. 1.路飞学成表设计: 2.将2个价格策略表合并1张表. 3.如果再加一张表,那价格策略表的表结构会发生改变.  这样不合理的,我们的表结构一般设计完就不会 ...

  3. 「HNOI2018」毒瘤

    「HNOI2018」毒瘤 解题思路 先考虑只有一棵树的情况,经典独立集计数. \[ dp[u][0]=\prod (dp[v][0]+dp[v][1]) \\ dp[u][1]=\prod dp[v] ...

  4. luoguP4492 [HAOI2018]苹果树 组合计数 + dp

    首先,每个二叉树对应着唯一的中序遍历,并且每个二叉树的概率是相同的 这十分的有用 考虑\(dp\)求解 令\(f_i\)表示\(i\)个节点的子树,根的深度为\(1\)时,所有点的期望深度之和(乘\( ...

  5. 【20181030T2】字胡串【分治+双指针】

    题面 [正解] 一眼分治 哎\(O(N^2)\)有50分,先敲了 等下,由于最大的数或进去了,所以有\(g(T) \geq f(T)\) 也就是说,我们用\(n \times (n-1) /2\)算出 ...

  6. SCP用法

    scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file] [-l limit] [-o ssh_option] [-P port ...

  7. OPENCV----在APP性能测试中的应用(一)

    应用项目:  APP的性能测试 应用场景:  APP启动速度  视频开播速度 加载速度  等~~ 缘来:  基于APP日志和UiAutomator的测试方案,测试结果不能直白且精确的反应,用户的体验 ...

  8. (转)js中的hasOwnProperty和isPrototypeOf方法

    hasOwnProperty:是用来判断一个对象是否有你给出名称的属性或对象.不过需要注意的是,此方法无法检查该对象的原型链中是否具有该属性,该属性必须是对象本身的一个成员.isPrototypeOf ...

  9. EJB (Enterprise Java Bean) 理解

    做开发有段时间了,一直似懂非懂的. http://blog.csdn.net/jojo52013145/article/details/5783677

  10. 连接本地websocket服务延迟的问题

    今天用C#编写了一个Chrome Remote Debugger的客户端程序,发现使用rest和websocket程序时第一次连接的时候特别慢,大概每次都要消耗一秒左右,而用chrome直接连接却没有 ...