Giter VIP home page Giter VIP logo

mcsmtabbarkit's Introduction

MCSMTabBarKit

This is work in progress to provide a custom Tab Bar (and Tab Bar Controller) for situations where the default Tab Bar Controller UITabBarController isn't appropriate.

Examples of where a custom Tab Bar might be useful are:

  • To customize the Look and Feel
  • Positioning of the Tab Bar
  • Illegal Behaviour, such as having a Tab Bar Controller in a Navigation Controller

Currently MCSMTabBar doesn't support badges or drag an drop customization.

MCSMTabBar

To use MCSMTabBar you simply need to initialize an instance and become its Data Source and more than likely its Delegate too:

MCSMTabBar *tabBar = [[MCSMTabBar alloc] initWithStyle:MCSMTabBarStyleDefault];
tabBar.tabBarDataSource = (id<MCSMTabBarDataSource>)self;
tabBar.tabBarDelegate = (id<MCSMTabBarDelegate>)self;

If you want to customize the layout of the Tab Bar you will want to subclass MCSMTabBar and set the style to MCSMTabBarStyleCustom

The Data Source only has 2 methods both of which are required:

@protocol MCSMTabBarDataSource <NSObject>

@required
- (NSUInteger)numberOfTabsInTabBar:(MCSMTabBar *)tabBar;
- (MCSMTabBarItemView *)tabBar:(MCSMTabBar *)tabBar tabBarItemViewForTabAtIndex:(NSUInteger)index;

@end

The Delegate has two optional methods for managing selection and one for managing the width of each tab:

@protocol MCSMTabBarDelegate <NSObject>

@optional
- (BOOL)tabBar:(MCSMTabBar *)tabBar shouldSelectTabAtIndex:(NSUInteger)index;
- (void)tabBar:(MCSMTabBar *)tabBar didSelectTabAtIndex:(NSUInteger)index;
- (CGFloat)tabBar:(MCSMTabBar *)tabBar widthForTabAtIndex:(NSInteger)index;

@end

MCSMTabBarItemView

MCSMTabBarItemView works a lot like UITableViewCell, you simply create one with the relevant data and carry out any layout customization in layoutSubviews

- (MCSMTabBarItemView *)tabBar:(MCSMTabBar *)tabBar tabBarItemViewForTabAtIndex:(NSUInteger)index{

	MCSMTabBarItemView *tabBarItemView = nil;

	tabBarItemView = [[[MCSMTabBarItemView alloc] initWithStyle:tabBar.style] autorelease];
	
	[tabBarItemView setTitle:title];
	[tabBarItemView setImage:image];
	[tabBarItemView setSelectedImage:selectedImage];

	return tabBarItemView;
}

MCSMTabBarController

MCSMTabBarController is designed to be a replacement for UITabBarController, it automatically creates a MCSMTabBar (if one isn't set) and supplies a MCSMTabBarItemView for every UIViewController in the Tab Bar.

You can either initalize one with a style:

MCSMTabBarController *tabBarController = [[MCSMTabBarController alloc] initWithStyle:MCSMTabBarStyleDefault];

Or with a Tab Bar:

MCSMTabBar *tabBar = [[MCSMTabBar alloc] initWithStyle:MCSMTabBarStyleDefault];
MCSMTabBarController *tabBarController = [[MCSMTabBarController alloc] initWithTabBar:tabBar];

You can also set the Tab Bar's position:

tabBarController.tabBarPosition = MCSMTabBarControllerTabBarPositionTop;

Then set the view controllers you want to be in the Tab Bar Controller:

[tabBarController setViewControllers:viewControllers];

If you want to customize the MCSMTabBarItemViews in the Tab Bar, you can become the Tab Bar Controller's Data Source and Implement tabBarController:tabBarItemViewForViewController:

@protocol MCSMTabBarControllerDataSource <NSObject>

@optional
- (MCSMTabBarItemView *)tabBarController:(MCSMTabBarController *)tabBarController tabBarItemViewForViewController:(UIViewController *)viewController;

@end

Like UITabBarController MCSMTabBarController has numerous delegate methods to handle selection and to handle UINavigationControllers so hidesBottomBarWhenPushed can be supported:

@protocol MCSMTabBarControllerDelegate <NSObject>

@optional

- (CGFloat)tabBarController:(MCSMTabBarController *)tabBarController widthForTabAtIndex:(NSInteger)index;
	
- (BOOL)tabBarController:(MCSMTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;
- (void)tabBarController:(MCSMTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;


- (BOOL)tabBarController:(MCSMTabBarController *)tabBarController shouldBecomeDelegateOfNavigationController:(UINavigationController *)navigationController;

- (void)tabBarController:(MCSMTabBarController *)tabBarController navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)tabBarController:(MCSMTabBarController *)tabBarController navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;

@end

mcsmtabbarkit's People

Contributors

objcolumnist avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.