UITabBar
来源:互联网 发布:腾讯云数据库招聘 编辑:程序博客网 时间:2024/05/01 00:11
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:tagStringdelegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
[alertView show];
NSLog(@"您选择的tag是:%d",tag);
}
详细demo见:https://github.com/tingxuan/TXUITabBarDemo
- UITabBar
- UITabBar
- UITabBar
- UITabbar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- UITabBar
- 自定义UITabBar
- 隐藏UITabBar
- 定制 UItabbar
- Custom UITabBar
- UITabBar&UINavigation
- 隐藏 UITabBar
- HTTP请求
- JSTL标签_详解
- python sys模块
- 兼容的“Microsoft.AspNet.Razor.zh-Hans”版本
- C#从视频截图的方法
- UITabBar
- C++ 之 原子操作 Interlocked系列函数多线程(四)
- JAVA进行类型转换
- 【CSDN常见问题解答】使用JNA调用Windows动态库
- C/C++代码(1):队列
- C/C++ via Windows (1) - first thing first
- ios 之contentmode
- linux设备模型之i2c子系统
- office2003word解除安全模式启动