iOS 自定義TabBar

首先看看效果

效果圖
參考 (BATabBarController)

點擊獲取DOME

pod 'QWTabBar'

實現(xiàn)思路

創(chuàng)建一個視圖覆蓋在系統(tǒng)的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 = @[@"首頁",@"任務(wù)",@"動態(tài)",@"活動",@"我的"];

for(int i =0;i<array.count;i++)
{
    UIViewController *vc = [[NSClassFromString(array[i]) alloc] init];
    [array replaceObjectAtIndex:i withObject:vc];
    
}
self.viewControllers = array;
//覆蓋系統(tǒng)的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];

設(shè)置角標

    [[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;

當(dāng)前選中的下標

@property (nonatomic, assign) NSInteger selectIndex;

當(dāng)前選中的 TabBar

 @property (nonatomic, strong) QWTabBarItem *tabBarItem;

 @property (nonatomic, weak) id <QWTabBarDelegate>delegate;

創(chuàng)建方法

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

設(shè)置角標

 -(void)setBadge:(NSInteger)count index:(NSUInteger)index;
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容