您好,登錄后才能下訂單哦!
一.刪除系統(tǒng)的標(biāo)簽欄上的按鈕(tabbarItem)
//設(shè)置tabbar的背景
[self.tabBar setBackgroundImage:[UIImage p_w_picpathNamed:@"tab_bg_all.png"]];
//刪除系統(tǒng)的tabbarItem
NSArray *array = self.tabBar.subviews;
//注意:UITabBarButton是一個(gè)私有的API,沒有公開出來
//遍歷tabbar中所有的子視圖,并且移除tabbarItem
for (UIView *view in array) {
Class cls = NSClassFromString(@"UITabBarButton");
if ([view isKindOfClass: cls]) {
//移除tabbar上的按鈕
[view removeFromSuperview];
}
}
//創(chuàng)建自己的圖片
//創(chuàng)建選擇視圖
_selectedImgView = [[UIImageView alloc] initWithImage:[UIImage p_w_picpathNamed:@"selectTabbar_bg_all1"]];
_selectedImgView.frame = CGRectMake(0, 0, 49, 49);
[self.tabBar addSubview:_selectedImgView];
//創(chuàng)建按鈕
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;
}
當(dāng)push到二級(jí)界面時(shí),隱藏標(biāo)簽欄
在自定義初始化方法中
self.hidesBottomBarWhenPushed = YES;
二,情況二,隱藏系統(tǒng)的標(biāo)簽欄,自定義標(biāo)簽欄
self.tabBar.hidden = YES;
_taBarView = [[UIImageView alloc]initWithFrame:CGRectMake(0, kScreenHeight-55, kScreenWidth, 55)];
當(dāng)push到二級(jí)界面時(shí),隱藏標(biāo)簽欄
#pragma mark - UINavigationControllerDelegate
//進(jìn)入到二級(jí)界面以后隱藏標(biāo)簽欄(自定義的)
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//獲取標(biāo)簽欄
MainTabBarViewController *mainBar = (MainTabBarViewController *)self.tabBarController;
//當(dāng)前控制器的個(gè)數(shù)
NSInteger count = self.viewControllers.count;
if (count == 1) {
//顯示標(biāo)簽欄
[UIView animateWithDuration:0.2 animations:^{
mainBar.taBarView.right = kScreenWidth;
}];
}else if (count == 2){
[UIView animateWithDuration:0.2 animations:^{
mainBar.taBarView.right = 0;
}];
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。