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);
}

时间: 2024-08-03 04:14:43

iOSTab bar的相关文章

Windows 7样式地址栏(Address Bar)控件实现

介绍 从Vista开始,地址栏就有了很大的改变,不知道大家有什么感觉,笔者觉得很方便,同时又兼容之前的功能,是个很不错的创新.不过,微软并不打算把这一很酷的功能提供给广大的开发人员. 本文提供了一个简单的Address Bar实现,使用.NET 2.0和VS2008. 它是基于一个简单的树型遍历实现的,同时适用于各种级联数据. Demo中提供的是一个非常简单的示例,可以浏览文件系统.这里这是展示它是如何工作的. 使用代码 了解实现最简单的办法就是直接下载源代码,然后打开玩玩看- 在Design-

codeforces 598E E. Chocolate Bar(区间dp)

题目链接: E. Chocolate Bar time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have a rectangular chocolate bar consisting of n × m single squares. You want to eat exactly k squares, so you ma

安卓项目开发实战(1)--首页顶部菜单BAR实现

从今天开始,我将开始自己手写一个星座运势的项目,星座运势的数据来源采用MYAPI的星座数据,客户端完全自己实现. 这个系列主要是讲工程中主要界面的布局展示和一些项目中的难点解析.由于本人刚自学安卓不久,请各位大神拍砖时手下留情. 第一个讲讲首页顶部的BAR的实现 现在的APP据我观察顶部都会涉及一个BAR,主要作用就是提示和导航, 先来看下实际的效果 那么如何实现这样一个效果呢? 具体做法是在页面布局里嵌套一个顶部导航菜单的布局 <?xml version="1.0" encod

(Android UI)Action Bar

Action Bar 指明用户当前所在的界面,添加多个功能性按键和下拉式选择框,以提供能多功能. 主题一:让应用具备ActionBar 可能条件一:Support Android 3.0(API 11) and Above Only 步骤一:在<Application>标签中指明theme属性值,android:theme="@android:style/Theme.Hole",即可让应用具备ActionBar <application android:name=&q

《iOS Human Interface Guidelines》——Toolbar Bar

工具栏 工具栏包含了执行与屏幕视图中的对象相关的操作的控件. 一个工具栏: 是半透明的 在iPhone上永远出现在屏幕视图的底部边缘.在iPad上也可以出现在屏幕视图的顶部边缘. 可以在键盘出现时.用户做一个手势时或者抱哈你的视图控制器过渡成水平紧凑环境时隐藏. API NOTE 工具栏一般包含在导航控制器(管理一系列层级的自定义视图显示的对象)内.查看Displaying a Navigation Toolbar和UIToolbar Class Reference来学习更多关于在你的代码中定义

改变status bar的状态

两种改变status bar状态的方法 一 :(全局的) 直接在当前控制器中(一般是在navigationcontroller) //- (UIStatusBarStyle)preferredStatusBarStyle{ //    return UIStatusBarStyleLightContent; //} 二 :(可以更具需要改变状态栏显示效果 //代码如下 [UIApplication sharedApplication].statusBarStyle = UIStatusBarSt

布局文件预览:Rendering Problems Exception raised during rendering: Unable to find the layout for Action Bar.的解决

在android studio或者eclipse中打开layout文件,发现不能预览布局,提示以下错误: Rendering Problems Exception raised during rendering: Unable to find the layout for Action Bar. 解决办法:切换到design视图,选择低一点的api版本即可.

Demo on bar code printing using SAP Scripts/Smart forms

This document will explain the printing of bar code using SAP Scripts/Smart forms Target Readers: SAP-ABAP consultants with knowledge of layout designing. Definition:  Bar codes are often printed on labels to allow machine to read the data. SAP has p

WP 8.1 status bar

A status bar is the bar showing signal, battery and time on the top of the phone's screen. In WP8.1 we it's called status bar, but in WP8.0 it's called phone shell. Show progress bar in the status bar: var statusBar = Windows.UI.ViewManagement.Status