自定义标签栏

发布时间:2020-07-02 04:01:40 作者:jna_114
来源:网络 阅读:575

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

//设置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;
        }];
    }
   
}


推荐阅读:
  1. 自定义response
  2. 自定义session

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

图片 标签 自定义标签

上一篇:搭建Git服务器

下一篇:vuejs5-v-show指令

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》