自定义标签栏-创新互联

一.删除系统的标签栏上的按钮(tabbarItem)

创新互联是一家专注于成都网站建设、网站设计与策划设计,怀柔网站建设哪家好?创新互联做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:怀柔等地区。怀柔做网站价格咨询:18980820575

//设置tabbar的背景
   [self.tabBar setBackgroundImage:[UIImage p_w_picpathNamed:@"tab_bg_all.png"]];

   //删除系统的tabbarItem

   NSArray *array = self.tabBar.subviews;

   //注意:UITabBarButton是一个私有的API,没有公开出来
   //遍历tabbar中所有的子视图,并且移除tabbarItem
   for (UIView *view in array) {
       Class cls = NSClassFromString(@"UITabBarButton");
       if ([view isKindOfClass: cls]) {
           //移除tabbar上的按钮
           [view removeFromSuperview];
       }
   }

   //创建自己的图片

   //创建选择视图
   _selectedImgView = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"selectTabbar_bg_all1"]];
   _selectedImgView.frame = CGRectMake(0, 0, 49, 49);
   [self.tabBar addSubview:_selectedImgView];

   //创建按钮
   NSArray *imgArr = @[@"movie_home.png",
                       @"msg_new.png",
                       @"start_top250.png",
                       @"icon_cinema.png",
                       @"more_setting.png"];

   NSArray *titleArrray = @[@"电影", @"新闻", @"top", @"影院", @"更多"];

   CGFloat width = kScreenWidth / imgArr.count;
   CGFloat height = self.tabBar.height;

   for (int i = 0; i < imgArr.count; i++) {
       NSString *imgName = imgArr[i];

       NSString *title = titleArrray[i];

       MainTabbarItem *item = [[MainTabbarItem alloc] initWithFrame:CGRectMake(width * i, 0, width, height)
                                                          p_w_picpathName:imgName
                                                              title:title];

       item.tag = 2015 + i;
       [item addTarget:self action:@selector(clickItem:) forControlEvents:UIControlEventTouchUpInside];

       [self.tabBar addSubview:item];

       if (i == 0) {
           _selectedImgView.center = item.center;

       }

当push到二级界面时,隐藏标签栏

在自定义初始化方法中

       self.hidesBottomBarWhenPushed = YES;

二,情况二,隐藏系统的标签栏,自定义标签栏

self.tabBar.hidden = YES;

   _taBarView = [[UIImageView alloc]initWithFrame:CGRectMake(0, kScreenHeight-55, kScreenWidth, 55)];

当push到二级界面时,隐藏标签栏

#pragma mark - UINavigationControllerDelegate
//进入到二级界面以后隐藏标签栏(自定义的)

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
   //获取标签栏
   MainTabBarViewController *mainBar = (MainTabBarViewController *)self.tabBarController;
   //当前控制器的个数
   NSInteger count = self.viewControllers.count;
   if (count == 1) {
       //显示标签栏
       [UIView animateWithDuration:0.2 animations:^{
           mainBar.taBarView.right = kScreenWidth;
       }];
   }else if (count == 2){

       [UIView animateWithDuration:0.2 animations:^{
           mainBar.taBarView.right = 0;
       }];
   }

}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


当前标题:自定义标签栏-创新互联
本文来源:http://myzitong.com/article/dhhohh.html