美文网首页
iOS 自定义TabBar

iOS 自定义TabBar

作者: Mr卿 | 来源:发表于2019-12-16 17:45 被阅读0次

    首先看看效果

    效果图
    参考 (BATabBarController)

    点击获取DOME

    pod 'QWTabBar'
    

    实现思路

    创建一个视图覆盖在系统的TabBar上面

    NSMutableArray *array = [NSMutableArray arrayWithArray:@[@"UIViewController",@"UIViewController",@"UIViewController",@"UIViewController",@"TestViewController"]];
    NSArray *imgArray = @[@"homePage",@"task",@"complaint",@"home_activity",@"me"];
    NSArray *selectImageArray = @[@"homePage_select",@"task_select",@"complaint_select",@"home_activity_select",@"me_select"];
    NSArray *titles = @[@"首页",@"任务",@"动态",@"活动",@"我的"];
    
    for(int i =0;i<array.count;i++)
    {
        UIViewController *vc = [[NSClassFromString(array[i]) alloc] init];
        [array replaceObjectAtIndex:i withObject:vc];
        
    }
    self.viewControllers = array;
    //覆盖系统的tabBar
    self.qwTabBar = [[QWTabBar alloc] initWithTitles:titles itemImages:imgArray selectImages:selectImageArray];
    self.qwTabBar.delegate = self;
    self.qwTabBar.tintColor = [UIColor orangeColor];
    [self.tabBar addSubview:self.qwTabBar];
    

    设置角标

        [[QWTabBarController qwTabbarController].qwTabBar setBadge:122 index:4]; 
    

    tabBarItem

    @property (nonatomic, readonly, strong) NSMutableArray <QWTabBarItem *> *tabBarItems;
    

    标题

    @property (nonatomic, copy) NSArray <NSString *> *titles;
    

    默认图标 UIImage 类型 或者 NSString 类型

    @property (nonatomic, strong) NSArray *itemImages;
    

    选中图标 UIImage 类型 或者 NSString 类型

    @property (nonatomic, strong) NSArray *selectItemImages;
    

    默认标题颜色

    @property (nonatomic, strong) UIColor *defColor;
    

    选中标题颜色

    @property (nonatomic, strong) UIColor *tintColor;
    

    当前选中的下标

    @property (nonatomic, assign) NSInteger selectIndex;
    

    当前选中的 TabBar

     @property (nonatomic, strong) QWTabBarItem *tabBarItem;
    
     @property (nonatomic, weak) id <QWTabBarDelegate>delegate;
    

    创建方法

    -(instancetype)initWithTitles:(NSArray <NSString *> *)titles itemImages:(NSArray *)itemImgs selectImages:(NSArray *)selectImages;
    

    设置角标

     -(void)setBadge:(NSInteger)count index:(NSUInteger)index;

    相关文章

      网友评论

          本文标题:iOS 自定义TabBar

          本文链接:https://www.haomeiwen.com/subject/bjsdnctx.html