RDVTabBarController:一個非常完善的tabBarController,可以自定義角標個數,爽的停不上去。
RDVTabBarController地址:RDVTabBarController
Demo地址:歡送Star
闡明
此教程是旨在讓你疾速動手,如需愈加深層次的理解,請直接RDVTabBarController地址剖析即可;
運用
pod 'RDVTabBarController'
構造
RDVTabBar
@interface RDVTabBar : UIView
RDVTabBarController
@interface RDVTabBarController : UIViewController
RDVTabBarItem
@interface RDVTabBarItem : UIControl
RDVTabBarController Example Usage其實曾經很詳細了,接上去看初始化
//VString宏定義,為了就是更好的國際化言語,適配多言語,剛好此Demo也國際化了,可以參看https://github.com/sauchye/dev_notes/issues/4
#define VString(x) NSLocalizedString(x, nil)
- (void)setupViewControllers{
SYFirstViewController *firstVC = [[SYFirstViewController alloc] init];
SYSecondViewController *secondVC = [[SYSecondViewController alloc] init];
SYThirdViewController *thirdVC = [[SYThirdViewController alloc] init];
firstVC.title = VString(@"Home");
secondVC.title = VString(@"Found");
thirdVC.title = VString(@"Me");
self.firstNav = [[SYBaseNavigationController alloc] initWithRootViewController:firstVC];
self.secondNav = [[SYBaseNavigationController alloc] initWithRootViewController:secondVC];
self.thirdNav = [[SYBaseNavigationController alloc] initWithRootViewController:thirdVC];
[self setViewControllers:@[self.firstNav, self.secondNav, self.thirdNav]];
[self customizeTabBarForController];
}
NSInteger index = 0;
for (RDVTabBarItem *item in [[self tabBar] items])
{
item.titlePositionAdjustment = UIOffsetMake(0, 2.0);
[item setBackgroundSelectedImage:backgroundImage withUnselectedImage:backgroundImage];
UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",[tabBarItemImages objectAtIndex:index]]];
UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",[tabBarItemImages objectAtIndex:index]]];
[item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
[item setTitle:[tabBarItemTitles objectAtIndex:index]];
item.selectedTitleAttributes = @{
NSFontAttributeName: [UIFont boldSystemFontOfSize:12],
NSForegroundColorAttributeName:kNAVIGATION_BAR_COLOR,
};
item.unselectedTitleAttributes = @{
NSFontAttributeName: [UIFont boldSystemFontOfSize:12],
NSForegroundColorAttributeName:RGB(217, 217, 217),
};
[item setTitle:[tabBarItemTitles objectAtIndex:index]];
index++;
}
}
這樣你的tabBar根本搭建好了,但是還需求完善一些,比方,角標設置,push隱藏等。
Push隱藏tabBar,你只需求這樣即可 - (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}
設置角標數
[[self rdv_tabBarItem] setBadgeValue:@"3"];
RDVTabBarControllerDelegate,置信你看就會明白,好的辦法命名很重要啊~
/**
* Asks the delegate whether the specified view controller should be made active.
*/
- (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
/**
* Tells the delegate that the user selected an item in the tab bar.
*/
* (void)tabBarController:(RDVTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
結語
RDVTabBarController是一個很棒的第三方tabBarController,值得我們學習和考慮。
相比傳統第三方,你會發現可以很好的定制角標,這是極好的,當然你也可以自定義;
但是不能定義兩頭凹陷的tabBar,好早之前去哪兒就是兩頭凹陷一個tabBar,不過如今去哪兒也改成傳統的tabBar了;
–
更多討論,參見: http://www.IOS122.com/tag/rdvtabbarcontroller/
【RDVTabBarController】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!