码迷,mamicode.com
首页 > 其他好文 > 详细

[翻译] RDVTabBarController

时间:2014-12-16 09:53:27      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   ar   io   color   os   使用   sp   

RDVTabBarController

bubuko.com,布布扣

https://github.com/robbdimitrov/RDVTabBarController

效果:

bubuko.com,布布扣

 

  • Supports iPad and iPhone 支持iPad与iPhone
  • Supports landscape and portrait orientations 支持横竖屏切换动画
  • Can be used inside UINavigationController 可以用在UINavigationController里面
  • Customizable badges 可定制的提示标签

 

Installation 安装

CocoaPods - cocoaPods

If you‘re using CocoaPods, simply add pod ‘RDVTabBarController‘ to your Podfile.

如果你使用了CocoaPods,简单的pod ‘RDVTabBarController’ 到你的Podfile文件中就行了。

 

Drag & Drop - 拖到项目当中

Add the items from RDVTabBarController directory to your project. If you don‘t have ARC enabled, you will need to set a -fobjc-arc compiler flag on the .m source files.

直接将RDVTabBarController文件夹拖到你的项目当中。如果你的项目是MRC的,你需要在.m文件里面设置-fobjc-arc编译标签。

 

Example Usage - 使用示例

Initialize RDVTabBarController

初始化RDVTabBarController

The initialization is similar to the one for UITabBarController. Create an instance of the tabBarController and initialize its viewControllers.

初始化方法与UITabBarController类似,创建一个tabBarController的实例以及初始化控制器。

UIViewController *firstViewController = [[RDVFirstViewController alloc] init];
UIViewController *firstNavigationController = [[UINavigationController alloc]
                                               initWithRootViewController:firstViewController];

UIViewController *secondViewController = [[RDVSecondViewController alloc] init];
UIViewController *secondNavigationController = [[UINavigationController alloc]
                                                initWithRootViewController:secondViewController];

UIViewController *thirdViewController = [[RDVThirdViewController alloc] init];
UIViewController *thirdNavigationController = [[UINavigationController alloc]
                                               initWithRootViewController:thirdViewController];

RDVTabBarController *tabBarController = [[RDVTabBarController alloc] init];
[tabBarController setViewControllers:@[firstNavigationController, secondNavigationController,
                                       thirdNavigationController]];
self.viewController = tabBarController;

 

Customize RDVTabBarController - 定制RDVTabBarController

Each RDVTabBarItem has selectedBackgroundunselectedBackground and corresponding properties for the icons: selectedImage and unselectedImage.

每一个RDVTabBarItem都有选择被背景与未选择的背景,或者是对应于选择的图片与未选择的图片。

UIImage *finishedImage = [UIImage imageNamed:@"tabbar_selected_background"];
UIImage *unfinishedImage = [UIImage imageNamed:@"tabbar_normal_background"];
NSArray *tabBarItemImages = @[@"first", @"second", @"third"];

RDVTabBar *tabBar = [tabBarController tabBar];

[tabBar setFrame:CGRectMake(CGRectGetMinX(tabBar.frame), CGRectGetMinY(tabBar.frame), CGRectGetWidth(tabBar.frame), 63)];

NSInteger index = 0;
for (RDVTabBarItem *item in [[tabBarController tabBar] items]) {
    [item setBackgroundSelectedImage:finishedImage withUnselectedImage:unfinishedImage];
    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];

    index++;
}

 

Make the tab bar translucent - 可以让tab bar变得半透明

RDVTabBar has translucent property which determines how it is going to be handled.

RDVTabBar有着半透明色这个属性,他决定着怎么个透明方式。

RDVTabBar *tabBar = tabBarController.tabBar;

// After the tabBarController initialization
tabBar.translucent = YES;

// Customize the tabBar background
tabBar.backgroundView.backgroundColor = [UIColor colorWithRed:245/255.0
                                                        green:245/255.0
                                                         blue:245/255.0
                                                        alpha:0.9]];

// Inside the tabbed viewControllers
- (void)viewDidLoad {
    [super viewDidLoad];

    ...

    if (self.rdv_tabBarController.tabBar.translucent) {
        CGFloat tabBarHeight = CGRectGetHeight(self.rdv_tabBarController.tabBar.frame);
        UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, tabBarHeight, 0);

        self.tableView.contentInset = insets;
        self.tableView.scrollIndicatorInsets = insets;
    }
}

 

Requirements - 需要的环境

  • ARC 
  • iOS 5.0 or later
  • Xcode 5

 

Contact

Robert Dimitrov
@robbdimitrov

 

[翻译] RDVTabBarController

标签:style   blog   http   ar   io   color   os   使用   sp   

原文地址:http://www.cnblogs.com/YouXianMing/p/4166416.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!