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 ...
随机推荐
- windows2003通过iis配置ftp服务器
以前习惯于用filezilla作为windows的ftp服务器,但是现在新版本的filezilla已经不支持windows2003了,所以趁机试一下iis配置ftp服务器. 前面都是很常规的配置 参考 ...
- matlab实现贝塞尔曲线绘图pdf查看
贝塞尔曲线绘图方法: %Program 3.7 Freehand Draw Program Using Bezier Splines %Click in Matlab figure window to ...
- 第一章 Web MVC简介
Web MVC简介 1.1.Web开发中的请求-响应模型: 在Web世界里,具体步骤如下: 1. Web浏览器(如IE)发起请求,如访问hao123主页 2. Web服务器(如Tomcat)接收请 ...
- cocos2d下,优秀骨骼spine的换装思路
语文老师说,文章要有个好开头!!! 最近正在引入spine骨骼代替dragon bone骨骼,既然要替代,那么原先在dragon bone上的一些额外需求,不管dragon bone上能不能实现,都应 ...
- c#之委托总结
1.委托的声明和编译原理 声明委托: delegate void Translate(string str); 通过反编译之后可得下面代码 private sealed class Translate ...
- AFNetworking VS ASIHTTPRequest
AFNetworking和ASIHTTPRequest,大致如下: 使用上:AFN是用上较ASI略简单,但扩展不如ASI;AFN能按普通的block写法直接用闭包的写法,但是ASI不行,这样ASI的代 ...
- ssh 内在溢出
相信有一定java开发经验的人或多或少都会遇到OutOfMemoryError的问题,这个问题曾困扰了我很长时间,随着解决各类问题经验的积累以及对问题根源的探索,终于有了一个比较深入的认识. 在解决j ...
- oracle 字符集导入、导出 、转换
导入导出及转换 导入导出是我们常用的一个数据迁移及转化工具,因其导出文件具有平台无关性,所以在跨平台迁移中,最为常用. 在导出操作时,非常重要的是客户端的字符集设置,也就是客户端的NLS_LANG设置 ...
- Openstack Quantum project 更名为 Neuron
因为与磁带备份厂商Quantum商标冲突: The OpenStack Foundation has changed the name of its networking project from Q ...
- How to Enable 64-bit Processes for Enhanced Protected Mode in Internet Explorer 11 (IE11)
Information Enhanced Protected Mode (EPM) adds additional security to Protected Mode and includes ...