UITabBar
来源:互联网 发布:js value 编辑:程序博客网 时间:2024/05/01 02:21
ViewController.h文件
#import <UIKit/UIKit.h>
@interface ViewController :UIViewController<UITabBarDelegate>
@end
ViewController.m文件
#import "ViewController.h"
@interface ViewController ()
{
UIView * _view0; //TabBar上面的视图
}
@end
@implementation ViewController
//产生动画效果变化包括:1.位置变化 2.大小变化 3.拉伸变化 4.改变透明度 5.改变状态 6.改变视图顺序 7.旋转
- (void)viewDidLoad {
[superviewDidLoad];
//设置屏幕整体背景颜色
self.view.backgroundColor=[UIColorwhiteColor];
//加载TabBar
[self_loadTabBar];
//加载view
[self_loadView];
}
- (void) _loadView
{
//4个视图分别对应 TabBar的四个item 视图的高度 + TabBar的高度 =屏幕的高度
UIView * view1=[[UIViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];
view1.backgroundColor=[UIColorredColor];
UIView * view2=[[UIViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];
view2.backgroundColor=[UIColoryellowColor];
UIView * view3=[[UIViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];
view3.backgroundColor=[UIColorblueColor];
UIView * view4=[[UIViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];
view4.backgroundColor=[UIColorgreenColor];
_view0=[[UIViewalloc]initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height-49)];
//_view0.backgroundColor=[UIColor whiteColor];
_view0.tag =200;
[self.viewaddSubview:_view0];
[_view0addSubview:view2];
[_view0addSubview:view3];
[_view0addSubview:view4];
[_view0addSubview:view1];
view1.tag =201;
view2.tag =202;
view3.tag =203;
view4.tag =204;
}
#pragma mark - 加载TabBar
- (void) _loadTabBar
{
//TabBar 放在屏幕最下面--类似于导航栏 item 的个数没有限制
//设置TabBar的位置及长宽
UITabBar * tabBar=[[UITabBaralloc]initWithFrame:CGRectMake(0,self.view.frame.size.height-49,self.view.frame.size.width,49)];
tabBar.delegate =self;
//TabBar设置
/*
//透明效果----改变背景色
tabBar.backgroundColor=[UIColor redColor];
//改变样式
tabBar.barStyle=UIBarStyleBlack;
//设置背景图片
tabBar.backgroundImage=[UIImage imageNamed:@"bg1.jpg"];
*/
//添加TabBar上的 item类似于button 实质都是UIView
//1>添加方法1 定义UITabBarItem ,并加到数组
UITabBarItem * tb1=[[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemFavoritestag:101];
UITabBarItem * tb2=[[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarkstag:102];
//2>添加方法2 添加UITabBarItem 的 第三个item 自定义图片,未选中时保持原来的颜色
UIImage * img1=[[UIImageimageNamed:@"star_top250"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage * img2=[UIImageimageNamed:@"star_top250"];
UITabBarItem * tb3=[[UITabBarItemalloc]initWithTitle:@"hello"image:img1 selectedImage:img2];
tb3.tag =103;
//3>添加方法3
UITabBarItem * tb4=[[UITabBarItemalloc]initWithTitle:@"worldworldddddddddd"image:[UIImageimageNamed:@"msg_new"]tag:104];
//修改小图标下面的名字
NSDictionary * dic=@{NSFontAttributeName:[UIFontsystemFontOfSize:17]};
[tb1 setTitleTextAttributes:dicforState:UIControlStateNormal];
[tb2 setTitleTextAttributes:dicforState:UIControlStateNormal];
[tb3 setTitleTextAttributes:dicforState:UIControlStateNormal];
[tb4 setTitleTextAttributes:dicforState:UIControlStateNormal];
NSArray * array=@[tb1,tb2,tb3,tb4];
tabBar.items=array;
tabBar.selectedItem=array[0];
//添加到主视图
[self.viewaddSubview:tabBar];
}
#pragma mark - 代理方法
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSInteger tag = item.tag;
UIView * view = [self.viewviewWithTag:tag+100];
[UIViewbeginAnimations:nilcontext:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFromLeftforView:_view0cache:YES];
[_view0bringSubviewToFront:view];
[UIViewcommitAnimations];
}
@end
- UITabBar
- UITabBar
- UITabBar
- UITabbar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- 自定义UITabBar
- 隐藏UITabBar
- 定制 UItabbar
- Custom UITabBar
- UITabBar&UINavigation
- 隐藏 UITabBar
- 关于网络游戏防外挂的问题
- D3 scales and colors
- 克努斯-莫里斯-普拉特算法(Knuth–Morris–Pratt algorithm) c简单实现
- 使用boost::function错误
- vim使用过程中遇到的一系列问题
- UITabBar
- 实时显示iOS编写UI代码效果
- "iOS push全方位解析(一)【译文】"——iOS PUSH概述
- set,map用于统计输出
- Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
- 四月总结
- SSH纪实--最基本最基本的知识(二)
- Spring Validator和Hibernate Validator
- Spring+监听器+Quartz集群(3)——任务管理