UITabBar
2013-12-10 10:15
344 查看
UITabBar即选项卡,使用它比较简单,主要是创建UITabBarItem,然后添加到UITabBar的items里。
1、UITabBar的创建
UITabBar *tabBar = [[UITabBaralloc]initWithFrame:CGRectMake(0,420,
320,60)];
2、创建UITabBarItem
有两种方法:
initWithTabBarSystemItem、initWithTitle
这里用initWithTabBarSystemItem作演示
UITabBarItem *tabBarItem01 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemDownloadstag:1];
UITabBarItem *tabBarItem02 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemHistorytag:2];
UITabBarItem *tabBarItem03 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemContactstag:3];
UITabBarItem *tabBarItem04 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemMoretag:4];
系统的UITabBarItem的样式主要有以下几种:
typedef NS_ENUM(NSInteger, UITabBarSystemItem) {
UITabBarSystemItemMore,
UITabBarSystemItemFavorites,
UITabBarSystemItemFeatured,
UITabBarSystemItemTopRated,
UITabBarSystemItemRecents,
UITabBarSystemItemContacts,
UITabBarSystemItemHistory,
UITabBarSystemItemBookmarks,
UITabBarSystemItemSearch,
UITabBarSystemItemDownloads,
UITabBarSystemItemMostRecent,
UITabBarSystemItemMostViewed,
};
3、将UITabBarItems添加
NSMutableArray * tabBarItemArray = [NSMutableArrayarrayWithObjects:tabBarItem01,tabBarItem02,tabBarItem03,tabBarItem04,tabBarItem05,tabBarItem06,nil];
[tabBar setItems:tabBarItemArrayanimated:YES];
4、设置UITabBar的属性
tabBar.tintColor = [UIColorredColor];
5、添加delegate,并实现delegate的方法
tabBar.delegate =self;
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSInteger tag = item.tag;
NSString * tagString = [NSStringstringWithFormat:@"您选择了%d个tabBarItem",tag];
UIAlertView * alertView = [[UIAlertViewalloc]initWithTitle:@"选择了tabBarItem"message:tagString
delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
[alertView show];
NSLog(@"您选择的tag是:%d",tag);
}
详细demo见:https://github.com/tingxuan/TXUITabBarDemo
1、UITabBar的创建
UITabBar *tabBar = [[UITabBaralloc]initWithFrame:CGRectMake(0,420,
320,60)];
2、创建UITabBarItem
有两种方法:
initWithTabBarSystemItem、initWithTitle
这里用initWithTabBarSystemItem作演示
UITabBarItem *tabBarItem01 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemDownloadstag:1];
UITabBarItem *tabBarItem02 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemHistorytag:2];
UITabBarItem *tabBarItem03 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemContactstag:3];
UITabBarItem *tabBarItem04 = [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemMoretag:4];
系统的UITabBarItem的样式主要有以下几种:
typedef NS_ENUM(NSInteger, UITabBarSystemItem) {
UITabBarSystemItemMore,
UITabBarSystemItemFavorites,
UITabBarSystemItemFeatured,
UITabBarSystemItemTopRated,
UITabBarSystemItemRecents,
UITabBarSystemItemContacts,
UITabBarSystemItemHistory,
UITabBarSystemItemBookmarks,
UITabBarSystemItemSearch,
UITabBarSystemItemDownloads,
UITabBarSystemItemMostRecent,
UITabBarSystemItemMostViewed,
};
3、将UITabBarItems添加
NSMutableArray * tabBarItemArray = [NSMutableArrayarrayWithObjects:tabBarItem01,tabBarItem02,tabBarItem03,tabBarItem04,tabBarItem05,tabBarItem06,nil];
[tabBar setItems:tabBarItemArrayanimated:YES];
4、设置UITabBar的属性
tabBar.tintColor = [UIColorredColor];
5、添加delegate,并实现delegate的方法
tabBar.delegate =self;
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSInteger tag = item.tag;
NSString * tagString = [NSStringstringWithFormat:@"您选择了%d个tabBarItem",tag];
UIAlertView * alertView = [[UIAlertViewalloc]initWithTitle:@"选择了tabBarItem"message:tagString
delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
[alertView show];
NSLog(@"您选择的tag是:%d",tag);
}
详细demo见:https://github.com/tingxuan/TXUITabBarDemo
相关文章推荐
- UITabBarController更换tabBar背景图片
- 改造 UITabBarController
- 转-UITabBar各部分自定义设置
- UITabBarController TabBarItem 点击事件
- UITabBarController的使用(整理)
- UITabBar 中viewcontroller 里 切换UITable的 viewcontroller的方法
- 变相隐藏UITabBarController的TabBar
- ios学习之UITabBar(标签栏)
- UITabBarController
- UITabBarController使用详解
- UITabBarController使用详解
- UITabBarController的简单使用
- how-to-hide-uitabbarcontroller(转)
- UITabBarItem文字的设置
- 技巧-导航控制器和UITabBar控制器结合使用
- 有关UIView,UIButton,UITabBarItem,UITabBarController的基础
- 搞搞UITabBar——iOS从零单排
- UITabBarController使用详解
- UITabBarController的外观修改总结
- UITabbar 相关属性设置