UITabBar

来源:互联网 发布:vscode for xp 编辑:程序博客网 时间:2024/05/17 23:33

UITabBar
1.介绍 在一个app中,UITabBar对象控制在不同的任务、试图或模式间的切换,标签栏包含于标签栏控制器中,这是一个可以管理一系列自定义视图显示的程序对象。 一般和UITabBarConmutroller对象结合使用(也能独立使用tab bars作为独立控制),tab bars总是显示在屏幕的底部,并且包含一个或多个UITabBarItem对象。tab bars的外观与背景图像或色调颜色可以按自己界面进行定制。
2.类型
(1)使用UITabBarController,该对象提供自己的tabbar对象,开发者必须配置这些对象。
(2)使用initWithFrame:自行创建,按自己需求创建
3.UITabBar和UIToolBar的不同
UITabBar目的是去转换和改变app的模式;使用标签栏可以让用户在同一组数据的不同视图中切换,或是在和 app 整体功能相关的不同子任务中切换。UIToolBar为用户显示一系列actions相关的当前内容;使用工具栏让用户对当前模态或页面上的元素进行操作 。
4.UITabBarDelegate
UITabBarController组织tab bar,作为它的代理。UITabBar类提供了允许用户重新排序,删除并将条目添加到标签栏,这个过程被称为自定义标签栏。当用户自定义tab bar时,标签栏委托将接收到消息。
5.配置tab bar 的item項(程序配置)-是否与UITabBarController相关联
(1)为了配置与UITabBarController相关联的tab bar,配置与tab bar controller 相关的view controller。tab bar 自动从与tab bar相关的每个view controller的tabBarItem属性中获取items
(2)直接使用tab bar的setItems方法配置tab bar的項
6.tab bar的項
每个tab bar的項的内容存储在UITabBarItem对象中,每个item包含一个题目和一个图片,tabBarItem的配置参考UITabBarItem
7.属性和方法的介绍
itemPositioning属性:在可利用的空间内怎样放置items,如果items较多,让用户显示哪个tabs要显示;beginCustomizingItems方法显示一个选择界面,让用户选择显示的tab bar的項。
(1)自定义Tab Bar Items
items
The items displayed by the tab bar.
- setItems:animated:
Sets the items on the tab bar, optionally animating any changes into position.
selectedItem
The currently selected item on the tab bar.
(2)定义Tab Bar外观
barStyle
The tab bar style that specifies its appearance.
translucent
A Boolean value that indicates whether the tab bar is translucent.
barTintColor
The tint color to apply to the tab bar background.
itemPositioning
The positioning scheme for the tab bar items in the tab bar.
itemSpacing
The amount of space (in points) to use between tab bar items.
itemWidth
The width (in points) of tab bar items.
tintColor
The tint color to apply to the tab bar items.
backgroundImage
The custom background image for the tab bar.
shadowImage
The shadow image to use for the tab bar.
selectionIndicatorImage
The image to use for the selection indicator.
(3)设置代理
delegate
The tab bar’s delegate object.
(4)支持用户自定义tab bar的方法
- beginCustomizingItems:(注意使用UI TabBarController饰不能使用此方法,自定义时使用)
Presents a standard interface that lets the user customize the contents of the tab bar.
- endCustomizingAnimated:
Dismisses the standard interface used to customize the tab bar.

(5)常量
UITabBarItemPositioning
Constants that specify tab bar item positioning.
(6)Instance Properties
customizing
unselectedItemTintColor
iOS开发–一些UITabBarItem属性的设置
字数418 阅读12049 评论8 喜欢20
Collection/Bookmark/Share for width under 768px
1.改变UITabBarItem 字体颜色
[[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]forState:UIControlStateNormal];
[[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor color WithHexString:”#00C8D3”],UITextAttributeTextColor,nil]forState:UIControlStateSelected];

设置tabbarItem选中的颜色为红色
2.改变UITabBarItem 字体颜色和大小
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, [UIFont fontWithName:@”Helvetica” size:12.0f],NSFontAttributeName,nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, [UIFont fontWithName:@”Helvetica” size:12.0f],NSFontAttributeName,nil] forState:UIControlStateSelected];

设置UITabBarItem 字体颜色和大小
这里需要注意的是在设置字体的时候要选择支持中文的字体,不然的话修改字号是无效的,比如字体设置成“ProximaNova-Semibold”,这种字体本身只支持英语的,不支持中文所以使用该字体并不能调整字体大小
3.改变UITabBarItem的选中和非选中图片
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:[[ServiceProviderViewController alloc] init]];
nav1.tabBarItem.image = [ImageNamed(@”tabicon1_unselect”) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav1.tabBarItem.selectedImage = [ImageNamed(@”tabicon1_select”) imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav1.tabBarItem.title = @”服务商”;

改变UITabBarItem的选中和非选中图片
4.改变UITabBarController的颜色
UIView*mView=[[UIViewalloc]initWithFrame:CGRectMake(0,0,320,48)];//这是整个tabbar的颜色
[mViewsetBackgroundColor:[UIColorcolorWithPatternImage:[UIImageimageNamed:@”tabbar.png”]]];
[tab.tabBarinsertSubview:mViewatIndex:1];
mView.alpha=0.8;

设置UITabBar的颜色
5.如何隐藏系统自带的tabbar
有时候有的页面并不需要显示tabbar,但是返回的时候要显示tabbar,举个例子A->B 当A push到 B 时需要设置self.navigationController.hidesBottomBarWhenPushed= YES;

A页面的设置
同时在B页面要
- (void)viewWillAppear:(BOOL)animated
{
[superviewWillAppear:animated];
self.tabBarController.tabBar.hidden=YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
[superviewWillDisappear:animated];
self.tabBarController.tabBar.hidden=NO;
}

0 0
原创粉丝点击