Giter Site home page Giter Site logo

rdvtabbarcontroller's Introduction

RDVTabBarController

iPad screenshot

iPhone screenshot

  • Supports iPad and iPhone
  • Supports landscape and portrait orientations
  • Can be used inside UINavigationController
  • Customizable badges

Installation

CocoaPods

If you're using CocoaPods, simply add pod 'RDVTabBarController' to your 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.

Example Usage

Initialize RDVTabBarController

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

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

Each RDVTabBarItem has selectedBackground, unselectedBackground and corresponding properties for the icons: selectedImage and unselectedImage.

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

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

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 8.0 or later
  • Xcode 11

Contact

Robert Dimitrov
@robbdimitrov

License

RDVTabBarController is available under the MIT license. See the LICENSE file for more info.

rdvtabbarcontroller's People

Contributors

andreyvit avatar antiraum avatar kablaize avatar kohtenko avatar nikhilsh avatar ocarol avatar rathawut-l avatar robbdimitrov avatar sean-wang avatar stefreak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rdvtabbarcontroller's Issues

ios7 swipe back bug

when push a new viewcontroller,set the tabbar hide, then in the new viewcontroller, swipe to go back to first viewcontroller,offset of the contentview will be abnormal. It shows only in ios7.0+.
image

tabbar shows unexpectly

hi,
imagine now i was in ViewController A(tab was show), and then i push a ViewController B(i have made the tab hide). now it was working fine.then i present a new ViewController C above B,and when the C dismissed,the tab bar show again.
it was unexpectly.
i check the code,and find that in RDVTabBarController.m

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    CGSize viewSize = self.view.frame.size;
    CGFloat tabBarHeight = CGRectGetHeight([[self tabBar] frame]);
    if (!tabBarHeight) {
        tabBarHeight = 49;
    }

    [[self tabBar] setFrame:CGRectMake(0, viewSize.height - tabBarHeight, viewSize.width, tabBarHeight)];
    [[self contentView] setFrame:CGRectMake(0, 0, viewSize.width, viewSize.height -
                                            [[self tabBar] minimumContentHeight])];

    [self setSelectedIndex:[self selectedIndex]];
}

and it's not check the tab bar status,and make it always show.

Fresh cocoapods podspec

Could you please update podspec in CocoaPods Specs repo?

Spent recently 3 hours to find bug with strong delegate in RDVTabBar :)

_selectedTitleAttributes does not have an initial value

in RDVTabBarItem.m

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Setup defaults
        _title = @"";
        _titlePositionAdjustment = UIOffsetZero;
        _selectedTitleAttributes = ??

that cause sometimes the title label not draw properly.

transparent background

is there a way to create a transparent background on the tab bar?
I tried creating clearcolor in tabbar controller replacing the graycolor but white background is still showing up.

you can see my tabbar design.. that's the reason why I need transparent background.

screen shot 2013-08-18 at 7 30 17 am

Override delegates

Is it possible to override RDVTabBarDelegate methods and put it into APPDelegate using protocols?

- (void)tabBar:(RDVTabBar *)tabBar didSelectItemAtIndex:(NSInteger)index ;
- (BOOL)tabBar:(RDVTabBar *)tabBar shouldSelectItemAtIndex:(NSInteger)index;

i want to decide what to do when the user touch the second time at the same item, eg: if the user touches once, it will open the viewController2, and if he touches again, it will close the viewController2, and showviewController1

something like:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    _timelineVC         = [Timeline_ViewController new];
    _notificationsVC    = [Notifications_ViewController new];
    _createPostVC       = [CreatePost_ViewController new];
    _promotionVC        = [Promotion_ViewController new];
    _perfilVC           = [UserPerfil_ViewController new];

   rdv_tabBarController = [[RDVTabBarController alloc]init];
   rdv_tabBarController.delegate = self;

    [rdv_tabBarController setViewControllers:@[_timelineVC, _notificationsVC, _createPostVC, _promotionVC, _perfilVC ]];
    self.viewController = rdv_tabBarController;

    [self customizeTabBarForController:rdv_tabBarController];
    [self.window setRootViewController:self.viewController];

    [self.window makeKeyAndVisible];
}


//***********************************************************************************
- (void)tabBar:(RDVTabBar *)tabBar didSelectItemAtIndex:(NSInteger)index {

    if (index < 0 || index >= [[rdv_tabBarController viewControllers] count]) {
        return;
    }

    if ([rdv_tabBarController selectedViewController] == [rdv_tabBarController viewControllers][index]) {
        if (index == 2)  index = 0;
    }


    [rdv_tabBarController setSelectedIndex:index];

    if ([[rdv_tabBarController delegate] respondsToSelector:@selector(tabBarController:didSelectViewController:)]) {
        [[rdv_tabBarController delegate] tabBarController:rdv_tabBarController didSelectViewController:[rdv_tabBarController viewControllers][index]];
    }
}

//***********************************************************************************

- (BOOL)tabBar:(RDVTabBar *)tabBar shouldSelectItemAtIndex:(NSInteger)index {
    if ([[rdv_tabBarController delegate] respondsToSelector:@selector(tabBarController:shouldSelectViewController:)]) {
        if (![[rdv_tabBarController delegate] tabBarController:rdv_tabBarController shouldSelectViewController:[rdv_tabBarController viewControllers][index]]) {
            return NO;
        }
    }
    if ([rdv_tabBarController selectedViewController] == [rdv_tabBarController viewControllers][index]) {
        if (index != 2) {
            return NO;
        }
    }
    return YES;
}



[[self rdv_tabBarController] setTabBarHidden:NO animated:YES]; is invalid

I need set [[self rdv_tabBarController] setTabBarHidden:YES animated:YES]; in viewWillDisappear and set [[self rdv_tabBarController] setTabBarHidden:NO animated:YES]; in viewWillAppear.

Copy and paste the code above into RDVTabBarController's demo (RDVFirstViewController.m and RDVSecondViewController.m), I found when I press Second button, the tabBar will disappear and never appear.

can't update badge

  • (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    // Custom initialization
    [self awakeFromNib];
    }
    return self;
    }
  • (void)awakeFromNib
    {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshNum:) name:@"refreshCartNum" object:nil];
    }
  • (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    }
  • (void)refreshNum:(NSNotification *)notification
    {
    NSString *num = notification.object;
    [self.rdv_tabBarItem setBadgeValue:num];
    }

I add a notification like this, - (void)refreshNum:(NSNotification *)notification,this method works , but the badge does't change;

orientation issue

In landscape mode its not working correctly.
Tableview goes 13px under in tabbar, please help me if any one has solved this issue.

Change the Title Color

Currently i am facing issue w.r.t changing color of the tab bar title.
I want when tab bar is selected it should displayed different title color and when it is unselected it should displayed different title color.
How to achieve this?

a bug in ios7.0

when the ios sdk is 7.0, it has a bug when pop the viewcontroller,hope you fix it,I can’t find the reasen.

Indicator start stop

Hi
Thanks for the great project. In which method inside can I start and stop indicator? I need to show indicator until another tab open.

iOS 6 support in latest version broken

The latest version crashes when ran on iOS 6. The reason is because of line 122 in RDVTabBarController.m.

[self setNeedsStatusBarAppearanceUpdate];

Needs changed to:

if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) 
{
        [self setNeedsStatusBarAppearanceUpdate];
}

how to get the current display height of viewController's view

i want to get the display height (self.view.bounds.size.height) of current viewController's view but the value is not correct, the value is always more than correct value.(RDVTabBar 's height value), i want a value
except the UINavigationBar's height and RDVTabBar 's height just a display height, how to get it Thanks~

Translucent bar

How can be the standard translucency effect achieved with RDVTabBarController?

remove old items when setting new

  • (void)setItems:(NSArray *)items {
    for (RDVTabBarItem *item in items) {
    [item removeFromSuperview];
    }

    _items = [items copy];
    for (RDVTabBarItem *item in items) {
    [item addTarget:self action:@selector(tabBarItemWasSelected:) forControlEvents:UIControlEventTouchDown];
    [self addSubview:item];
    }
    }


Maybe remove old items

  • (void)setItems:(NSArray *)items {
    for (RDVTabBarItem *item in _items) {
    // other code
    }
    ...

Frame incorrect after dismissing modal view after orientation change.

I am presenting a modal view over the tab bar controller. Then changing the orientation to landscape, once I dismiss the view the tab bar controller looks like this....

ios simulator screen shot 21 aug 2014 11 59 26

This seems to be in both iOS 7 & 8. Oddly I wasn't able to replicate it in the example app, wonder if you had any idea what might cause this odd behaviour? It seems the navigation controller for the tab has the wrong frame and the tab bar itself is missing offscreen.

Can't add badge

RDVTabBarItem currently does not support badges. Are there plans for that?

how to remove the white bottom view

If I changed a few methods RDVSecondViewController

  • (void)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear:animated];
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    NSLog(@"self.view.frame %@",NSStringFromCGRect(self.view.frame));
    }
  • (void)viewWillDisappear:(BOOL)animated
    {
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    [super viewWillDisappear:animated];
    }
  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [[self rdv_tabBarController] setSelectedIndex:2];
    }

qq20150908-1 2x

You will find below a white view when you second time press,
How to solve?

RDVTabBarController 中contentViewHeight计算不正确

if (![self isTabBarHidden]) {
tabBarStartingY = viewSize.height - tabBarHeight;
contentViewHeight = viewSize.height - [[self tabBar] minimumContentHeight];
}

[[self tabBar] setFrame:CGRectMake(0, tabBarStartingY, viewSize.width, tabBarHeight)];  // 这里的setFrame应该写在if判断里, 否则会导致[[self tabBar] minimumContentHeight] 返回0, 然后contentViewHeight 计算不正确

feture request ~

it's better to add hide/show tabbar implementation :)
if has animation, perfect!

In CocoaPods

CocoaPods 0.28.0 is available.

[!] Unable to find a specification for RDVTabBarController.

Saving and Restoring Application State

I want to apply State Preservation and Restoration in my app but this didn't work. I have checked your code and saw that this feature didn't support for this version. Can you support this feature for library? If you have any suggestion please let me know, I will try to implement it myself.

limit the tab only 5 tab

how i can limit the viewed tab only to 5 tab, because i want to insert 7 tab
so later i can change them by changing the index ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.