iOS 自定义TabBar

首先看看效果

效果图
参考 (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;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容