自定义TabBar 2 不需隐藏系统Tabbar

将自定义的button和label 添加到原有的Tabbar上 这样不需再考虑push时如何隐藏的问题,只要使用系统隐藏方法

首先看一下效果图 这种效果的实现 只需要首页 分类 发现我的 灰色切图一组,桔色切图一组,和拍摄按钮切图 白色背景不需切图 可用控件实现,如果UI给的切图有带弧边的白色背景图 并不需要使用它 如果使用背景图来实现 对于不同屏幕尺寸的适应会比较麻烦,容易变形。


效果图

1. 创建我的

MyTabBarViewController 继承于UITabBarController

.h文件中

#import <UIKit/UIKit.h>

@interface MyTabBarViewController :UITabBarController

// 创建自定义的tabbarView

@property (nonatomic,strong)UIView *tabbarView;

// 创建自定义Tabbar的几个按钮和标题label

@property (nonatomic,strong)UIButton *findButton;

@property (nonatomic,strong)UIButton *lanMuButton;

@property (nonatomic,strong)UIButton *huodongButton;

@property (nonatomic,strong)UIButton *wodeButton;

@property (nonatomic,strong)UILabel *findLabel;

@property (nonatomic,strong)UILabel *lanmuLabel;

@property (nonatomic,strong)UILabel *huodonglabel;

@property (nonatomic,strong)UILabel *wodeLabel;

@end

2. .m文件中的相关处理 创建控件 关联tabbar等

// 

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

    self = [superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];

    if (self) {

        self.tabBar.translucent = NO;

    }

    returnself;

}


- (void)viewDidLoad {

    [superviewDidLoad];

    [selfcreateView];

    [selfcreateTabbarView];

}

- (void)createView{

设置tag值 与按钮点击关联

    //发现

    FindViewController *findVc = [[FindViewControlleralloc]init];

    FLGNanViewController *findNaVC = [[FLGNanViewControlleralloc]initWithRootViewController:findVc];

    findVc.tabBarItem.tag =1000;

    //栏目

    ClassifyViewController *lanmuvc = [[ClassifyViewControlleralloc]init];

    FLGNanViewController *lanmuNavc = [[FLGNanViewControlleralloc]initWithRootViewController:lanmuvc];

    lanmuvc.tabBarItem.tag =2000;

    //相机

    UIViewController *view = [[UIViewControlleralloc]init];

    //活动

    HuoDongViewController *hudongVC = [[HuoDongViewControlleralloc]init];

    FLGNanViewController *huoDongNavic = [[FLGNanViewControlleralloc]initWithRootViewController:hudongVC];

    hudongVC.tabBarItem.tag =3000;

    //我的

    WodeViewController *wodeVc = [[WodeViewControlleralloc]init];

    FLGNanViewController *wodeNaVC = [[FLGNanViewControlleralloc]initWithRootViewController:wodeVc];

    wodeVc.tabBarItem.tag =4000;

    //

    self.viewControllers = [NSArrayarrayWithObjects:findNaVC, lanmuNavc,view, huoDongNavic, wodeNaVC,nil];

   

}


- (void)createTabbarView{

// 创建TabbarView 添加到系统Tabbar

    self.tabbarView = [[UIViewalloc]initWithFrame:CGRectMake(0, -15,self.view.frame.size.width,64)];

    self.tabbarView.backgroundColor = [UIColorwhiteColor];

    [self.tabBaraddSubview:self.tabbarView];

// 设置TabbarView 阴影效果

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值