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的更多相关文章

  1. 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") ...

  2. 编程中Foo, Bar 到底什么意思?

    1 前言 在很多国外计算机书本和一些第三份开源软件的Demo中经常用到两个英文单词Foo,Bar.这到底是什么意思呢?从步入屌丝界的IT生活见到这两个单词到现在我还是不知道这两个单词的真正含义,今天有 ...

  3. iOS第八课——Navigation Controller和Tab bar Controller

    今天我们要学习Navigation Controller和Tab bar Controller. Navigation Controller是iOS编程中比较常用的一种容器,用来管理多个视图控制器. ...

  4. status bar、navigationBar、tableView吸顶view设置

    1. 隐藏navigationBar self.navigationController.navigationBar.hidden = YES; 2. status bar设置 -(void)view ...

  5. 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 ...

  6. iOS7下隐藏status bar的详细研究

    info.plist文件中,View controller-based status bar appearance项设为YES,则View controller对status bar的设置优先级高于a ...

  7. Bar菜单

    简介 BarButtonItem:元素(按钮.子菜单.标签.编辑器等) this.barButtonItem3 = new DevExpress.XtraBars.BarButtonItem(); B ...

  8. Translucent Bar Android状态栏自定义颜色

    Android4.4 一个很重要的改变就是透明系统栏..新的系统栏是渐变透明的, 可以最大限度的允许屏幕显示更多内容, 也可以让系统栏和 Action Bar 融为一体, 仅仅留下最低限度的背景保护以 ...

  9. android隐藏底部虚拟键Navigation Bar实现全屏

    隐藏底部虚拟键Navigation Bar实现全屏有两种情况 第一种:始终隐藏,触摸屏幕时也不出现 解决办法:同时设置以下两个参数 View.SYSTEM_UI_FLAG_HIDE_NAVIGATIO ...

随机推荐

  1. 如何保持iOS上键盘出现时输入框不被覆盖

    在 iOS5 上请求显示键盘时,系统从屏幕底部将键盘滑入上来,位于应用的内容之上. (墙内:http://mikixiyou.iteye.com/blog/1488302) 如果屏幕中的内容项目比较多 ...

  2. [搜片神器]使用C#实现DHT磁力搜索的BT种子后端管理程序+数据库设计(开源)

    谢谢园子朋友的支持,已经找到个VPS进行测试,国外的服务器:http://www.sosobta.com   大家可以给提点意见... 出售商业网站代码,万元起,非诚勿扰,谢谢. 联系h31h31 a ...

  3. [原创汉化]linux前端神器 WebStorm8 汉化

    只汉化了linux版本 因为linux的工具没win多 不过汉化应该都通用的,自行尝试下. 汉化的不是很完全.有时间放出完全版本来.汉化是个体力活 转载随易,汉化不易,且转且注明 截图: http:/ ...

  4. find查找指定类型文件并删除

            问题描述:                      查找当前目录下指定类型的文件              问题解决:                     (1)find命令   ...

  5. VIM Taglist安装配置和使用

    问题描述:            VIM  Taglist安装于配置 问题解决:             (1)安装Taglist包      (2)解压taglist压缩包         (3)将 ...

  6. PE文件结构详解(六)重定位

    前面两篇 PE文件结构详解(四)PE导入表 和 PE文件结构详解(五)延迟导入表 介绍了PE文件中比较常用的两种导入方式,不知道大家有没有注意到,在调用导入函数时系统生成的代码是像下面这样的: 在这里 ...

  7. windows service 安装和卸载指令

    添加服务: cd C:\Windows\Microsoft.NET\Framework\v4.0.30319InstallUtil.exe D:\OneKeyWebSiteDeployment\Ser ...

  8. Splay树再学习

    队友最近可能在学Splay,然后让我敲下HDU1754的题,其实是很裸的一个线段树,不过用下Splay也无妨,他说他双旋超时,单旋过了,所以我就敲来看下.但是之前写的那个Splay越发的觉得不能看,所 ...

  9. hdu 1233 还是畅通工程(最小生成树,基础)

    题目 //也是标准的最小生成树啊,我就改一点点,不重新再打一遍增加熟练度了 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #inclu ...

  10. PHP中发送邮件的几种方法总结

    1. 使用 mail() 函数 没什么好讲的,就是使用系统自带的smtp系统来发送,一般是使用sendmail来发.这个按照各个系统不同而定.使用参考手册. 2. 使用管道的形式 昨天刚测试成功,使用 ...