RDVTabBarController--可自由定製的iOS底部導航控件

  • RDVTabBarController:一個十分完善的tabBarController,能夠自定義角標個數,爽的停不下來。
  • RDVTabBarController地址:<a href ="https://github.com/robbdimitrov/RDVTabBarController">RDVTabBarController</a>
  • Demo地址:<a href ="https://github.com/sauchye/SYTipsDemo">歡迎Star</a>

說明

  • 此教程是旨在讓你快速入手,如需更加深層次的瞭解,請直接RDVTabBarController地址分析便可;

使用

pod 'RDVTabBarController'

建議直接CocoaPods管理,對CocoaPods有興趣的童鞋能夠戳<a href="http://code4app.com/article/cocoapods-install-usage">cocoapods-install-usage</a>html

結構

RDVTabBar 
@interface RDVTabBar : UIView
RDVTabBarController
@interface RDVTabBarController : UIViewController
RDVTabBarItem
@interface RDVTabBarItem : UIControl

RDVTabBarController Example Usage其實已經很詳細了,接下來看初始化ios

//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];
}
- (void)customizeTabBarForController{

    //tabbar 背景圖片 tabbar_background
    UIImage *backgroundImage = [UIImage imageNamed:@"tabbar_background"];
    //選項卡圖片
    NSArray *tabBarItemImages;
  	//這裏添加tabBar icon圖片
    //= @[VString(@"First"), VString(@"Second"),VString(@"Third")];

    NSArray *tabBarItemTitles = @[VString(@"Home"), VString(@"Found"), VString(@"Me")];
    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,你只須要這樣便可git

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    }
  • 設置角標數github

    [[self rdv_tabBarItem] setBadgeValue:@"3"];
  • RDVTabBarControllerDelegate,相信你看就會明白,好的方法命名很重要啊~objective-c

    /**
     * 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;
  • 還有須要多等待你去發現...app


結語

RDVTabBarController是一個很棒的第三方tabBarController,值得咱們學習和思考。學習

  • 相比傳統第三方,你會發現能夠很好的定製角標,這是極好的,固然你也能夠自定義;
  • 可是不能定義中間凸起的tabBar,好早以前去哪兒就是中間凸起一個tabBar,不過如今去哪兒也改爲傳統的tabBar了;

本文,由咱們 iOS122 的小夥伴 @Sauchye​供稿,更多討論,參見: http://www.ios122.com/tag/rdvtabbarcontroller/code

相關文章
相關標籤/搜索