溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

自定義標簽欄

發布時間:2020-07-02 04:01:40 來源:網絡 閱讀:596 作者:jna_114 欄目:開發技術

一.刪除系統的標簽欄上的按鈕(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;
        }];
    }
   
}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女