iOSTab bar
http://www.apkbus.com/android-130504-1-1.html
#import
#import "FirstViewController.h"
#import "SecondViewController.h"
@interface ViewController : UIViewController
{
UIDatePicker *datePicker;
UITabBar *tabBar;
FirstViewController *firstViewController;
SecondViewController *secondViewCOntroller;
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// 初始化Tab Bar
tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 416, 320, 44)];
//设置Tab Bar上的交互属性为YES
[tabBar setUserInteractionEnabled:YES];
// 设置代理
[tabBar setDelegate:self];
// 设置TabBar的背景颜色
[tabBar setBackgroundColor:[UIColor purpleColor]];
// 设置tabBar的透明度
tabBar.alpha = 0.5f;
// 定义一个可变数组存放tab Bar Item
NSMutableArray *tabBarArray= [NSMutableArray array];
// 初始化一个Tab Bar Item 到数组中
[tabBarArray addObject:[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites
tag:1]];
[tabBarArray addObject:[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemHistory
tag:2]];
UIImage *image = [UIImage imageNamed:@"test48.png"];
[tabBarArray addObject:[[UITabBarItem alloc]initWithTitle:@"测试" image:image tag:3]];
// 给Tab Bar 添加数组里的tab Bar Item
[tabBar setItems:tabBarArray animated:NO];
[self.view addSubview:tabBar];
// datePicker宽度320像素和高度216像素,系统都设置好了,只需设置一下他的远点坐标,
datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
// 设置datePicker显示模式
[datePicker setDatePickerMode:UIDatePickerModeDateAndTime];
//DatePicker属于UIControl子类,可以触发事件,当滚动滑轮滑轮停下后就调用这个方法了
[datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:datePicker];
}
-(void)dateChanged:(id)sender
{
UIDatePicker *control = (UIDatePicker*)sender;
// 把当前控件设置的时间赋给date
NSDate *date = control.date;
// 将NSDate格式装换成NSString类型
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
// 设置日历显示格式
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
// 把日历时间传给字符串
NSString *strDate = [dateFormatter stringFromDate:date];
NSString *message = [[NSString alloc]initWithFormat:@"你选取的时间是:%@",strDate];
// 弹出一个警告
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示"
message:message
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
// 显示警告
[alert show];
}
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString *strDate = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@", strDate);
-(void)tabBar:(UITabBar *)tabBarBar didSelectItem:(UITabBarItem *)item
{
if (item.tag == 1) {
// [tabBar setSelectedItem:[tabBar.items objectAtIndex:0]];
NSLog(@"---->%d",item.tag);
if(firstViewController.view.superview==nil)
{
if (firstViewController.view==nil) {
FirstViewController *firstView = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil];
firstViewController=firstView;
}
[secondViewCOntroller.view removeFromSuperview];
// [self.view insertSubview:firstViewController.view atIndex:0];
[self.view addSubview:firstViewController.view];
}
else {
[secondViewCOntroller.view removeFromSuperview];
// [self.view insertSubview:firstViewController.view atIndex:0];
[self.view addSubview:firstViewController.view];
}
}
if (item.tag == 2) {
if (secondViewCOntroller.view.superview==nil) {
if (secondViewCOntroller.view == nil)
{
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondViewCOntroller=secondView;
}
[firstViewController.view removeFromSuperview];
[self.view insertSubview:secondViewCOntroller.view atIndex:0];
}
else {
[firstViewController.view removeFromSuperview];
[self.view insertSubview:secondViewCOntroller.view atIndex:0];
}
}
NSLog(@"---->%d",item.tag);
}
iOSTab bar的更多相关文章
- scala - multiple overloaded alternatives of method bar define default arguments
同名同位置默认参数不能overload def bar(i:Int,s:String="a"){} def bar(i:String,s:String="b") ...
- 编程中Foo, Bar 到底什么意思?
1 前言 在很多国外计算机书本和一些第三份开源软件的Demo中经常用到两个英文单词Foo,Bar.这到底是什么意思呢?从步入屌丝界的IT生活见到这两个单词到现在我还是不知道这两个单词的真正含义,今天有 ...
- iOS第八课——Navigation Controller和Tab bar Controller
今天我们要学习Navigation Controller和Tab bar Controller. Navigation Controller是iOS编程中比较常用的一种容器,用来管理多个视图控制器. ...
- status bar、navigationBar、tableView吸顶view设置
1. 隐藏navigationBar self.navigationController.navigationBar.hidden = YES; 2. status bar设置 -(void)view ...
- Bar codes in NetSuite Saved Searches(transport/reprint)
THIS IS A COPY FROM BLOG Ways of incorporating Bar Codes into your Netsuite Saved Searches. Code ...
- iOS7下隐藏status bar的详细研究
info.plist文件中,View controller-based status bar appearance项设为YES,则View controller对status bar的设置优先级高于a ...
- Bar菜单
简介 BarButtonItem:元素(按钮.子菜单.标签.编辑器等) this.barButtonItem3 = new DevExpress.XtraBars.BarButtonItem(); B ...
- Translucent Bar Android状态栏自定义颜色
Android4.4 一个很重要的改变就是透明系统栏..新的系统栏是渐变透明的, 可以最大限度的允许屏幕显示更多内容, 也可以让系统栏和 Action Bar 融为一体, 仅仅留下最低限度的背景保护以 ...
- android隐藏底部虚拟键Navigation Bar实现全屏
隐藏底部虚拟键Navigation Bar实现全屏有两种情况 第一种:始终隐藏,触摸屏幕时也不出现 解决办法:同时设置以下两个参数 View.SYSTEM_UI_FLAG_HIDE_NAVIGATIO ...
随机推荐
- c++类中的静态成员
静态成员和非静态成员的区别: 类静态成员用static修饰,类的静态成员属于类本身,而不属于类的某个具体对象,静态成员被类的所有对象共享,因此某个对象对静态成员(数据成员)的修改对其对象是可见的.而类 ...
- UIGestureRecongnizer 手势拦截
在一个scrollview添加了一个tap的手势事件,然后在scrollview上添加了几个Button,在ios6,ios7 中两个点击事件相安无事,但在ios5中按钮却无法点击,究其原因是因为在i ...
- MVC的Ajax的异步请求
MVC的Ajax的异步请求 在这里小写一下MVC的异步请求的一点小总结. 个人认为是有两种的,一种就是跟webform一样的,依旧是使用jQuery的$.get()方法,只是请求地址不同,webfor ...
- wap开发使用jquery mobile之后页面不加载外部css样式文件/js文件
场景: wap开发,使用jquery mobile之后不会加载外部自定义的css文件了,需要手动刷新才会加载,查看外部自定义的js文件也是一样. 解决办法: 1.在page下面添加css样式,就不要写 ...
- 【BZOJ】【3757】苹果树
树分块 orz HZWER http://hzwer.com/5259.html 不知为何我原本写的倍增求LCA给WA了……学习了HZWER的倍增新姿势- 树上分块的转移看vfk博客的讲解吧……(其实 ...
- 使用文本文件(.txt)进行数据存取的技巧总结(相当的经典)
使用文本文件(.txt)进行数据存取的技巧总结(相当的经典) 使用文本文件(.txt)进行数据存取的技巧总结 由于本帖内容较多,部分转自他人的心得,因此,凡转贴的地方仅用“----转----”标注,原 ...
- eclipse 开发技巧
1. ctrl+shift+r:打开资源 这可能是所有快捷键组合中最省时间的了.这组快捷键可以让你打开你的工作区中任何一个文件,而你只需要按下文件名或mask名中的前几个字母,比如applic*.xm ...
- POJ 2912 Rochambeau(难,好题,枚举+带权并查集)
下面的是从该网站上copy过来的,稍微改了一点,给出链接:http://hi.baidu.com/nondes/item/26dd0f1a02b1e0ef5f53b1c7 题意:有N个人玩剪刀石头布, ...
- POJ1328Radar Installation
http://poj.org/problem?id=1328 题的大意就是说在海里有小岛,坐标位置会给出,需要岸边的雷达覆盖所有的小岛,但雷达的覆盖范围有限,所以,需要最少的雷达覆盖所有的小岛,但若是 ...
- eclipse 或MyEclipse将工程进行移动的时候会对@Override报错的处理方法
有时候导入javaSE,javaEE,android 工程的时候,明明是刚刚用过的没有问题的工程,但重新导入的时候就报错. 提示The method ... must override a sperc ...