UITabBar

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:@"您选择了%dtabBarItem",tag];

    UIAlertView * alertView = [[UIAlertViewalloc]initWithTitle:@"选择了tabBarItem"message:tagString delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];

    [alertView show];

    NSLog(@"您选择的tag是:%d",tag);

}

详细demo见:https://github.com/tingxuan/TXUITabBarDemo

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值