Latest 1.0.1
Homepage https://github.com/aokizen/SPSlideTabBarController
License MIT
Platforms ios 7.0, requires ARC
Authors

SPSlideTabController

A TabBarController with top TabBar and slide content view.

Screenshot for Demo

demo

Installation

Installation with CocoaPods

Podfile

To integrate SPSlideTabBarController into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'

pod 'SPSlideTabBarController', '~> 1.0.1'

Then, run the following command:

$ pod install

Requirements

Minimum iOS Target: iOS 7.0

Usage

  1. SPSlideTabBarController

    • Initialize a SPSlideTabBarController
    TableViewController *tableViewController = [[TableViewController alloc] init];
    [tableViewController setTitle:@"table"];
    
    CollectionViewController *collectionViewController = [[CollectionViewController alloc] initWithCollectionViewLayout:[UICollectionViewFlowLayout new]];
    [collectionViewController setTitle:@"collection"];
    
    ScrollViewController *scrollViewController = [[ScrollViewController alloc] init];
    [scrollViewController setTitle:@"scroll"];
    
    ViewController *viewController = [[ViewController alloc] init];
    [viewController setTitle:@"general"];
    
    SPSlideTabBarController *slideTabBarController = [[SPSlideTabBarController alloc] initWithViewController:@[tableViewController, collectionViewController, scrollViewController, viewController] initTabIndex:2];
    • Selected a tab with a SPSlideTabBarController
    - (void)selectTabIndex:(NSUInteger)tabIndex animated:(BOOL)animated;
    • Add a UIViewController to a SPSlideTabBarController
    /**
     * add a viewController to the slideTabBarController
     *
     * 为当前的 slideTabBarController 增加一个 viewController
     *
     * @discussion the viewController and the tab bar item will be added at the last index by default.
     * @discussion 待加入的 viewController 和 tab bar item 会被默认加到最后一个
     */
    - (void)addViewController:(nonnull UIViewController *)viewController;
    
    /**
     * add a viewController to the slideTabBarController at the index
     *
     * 为当前的 slideTabBarController 增加一个 viewController,添加到 index 的位置
     */
    - (void)addViewController:(nonnull UIViewController *)viewController atIndex:(NSUInteger)tabIndex;
  2. Custom a slide tab bar

    a easy way to define a custom slide tab bar is to define a view which conforms to the protocol <SPSlideTabBarProtocol>.

    There are two defined custom slide tab bar already.

    • SPFixedSlideTabBar
    /**
     * a custom slide tab bar whose tabs' width is fixed which is depend on the slide tab bar's width.
     *    
     * 一个定制的 slide tab bar. 所有 tab 都是固定宽度的,具体宽度是多少是根据 tab bar 的宽度来均分计算的。
     */
    @interface SPFixedSlideTabBar : UIView <SPSlideTabBarProtocol>
    @end
    • SPSizingSlideTabBar
    /**
     * a custom slide tab bar whose tabs' width is depend on the content size of the tab.
     *
     * 一个定制的 slide tab bar. 所有 tab 的宽度都是根据 tab 的内容来自适应的。
     */
    @interface SPSizingSlideTabBar : SPFixedSlideTabBar
    @end
  3. Style slide tab bar item

    [[SPSlideTabBarItem appearance] setBarItemSelectedTextColor:[UIColor blueColor]];

    Then, a custom slideTabBar can call [[SPAppearance appearanceForClass:[item class]] startForwarding:item]; for each tabBarItem to apply the style.

    • example code

    In the method - (void)resetTabBarItemViews in the SPFixedSlideTabBar, there are following code:

    [self.slideTabBarItems enumerateObjectsUsingBlock:^(SPSlideTabBarItem *item, NSUInteger index, BOOL *stop) {
    
        /**
         * start apply the style to the item
         */
        [[SPAppearance appearanceForClass:[item class]] startForwarding:item];
    
        NSUInteger tag = index + 1000;
    
        UIButton *button = (UIButton *)[self.scrollView viewWithTag:tag];
        if (button == nil) {
            /**
             * initialize the button
             */
            button = [UIButton buttonWithType:UIButtonTypeCustom];
            ;
            ;
            [self.scrollView addSubview:button];
        }
    
        /**
         * style the button
         */
        if (item.attibutedTitle) {
            ;
        }
        else {
            ;
            ;
            ;
            ;
            ;
            ;
        }
    
        ;
    }];

License

SPSlideTabBarController is released under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "SPSlideTabBarController",
    "version": "1.0.1",
    "summary": "A TabBarController with top TabBar and slide content view.",
    "homepage": "https://github.com/aokizen/SPSlideTabBarController",
    "license": "MIT",
    "authors": {
        "aokizen": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/aokizen/SPSlideTabBarController.git",
        "tag": "1.0.0"
    },
    "source_files": "SPSlideTabBarController/SPSlideTabBarController/**/*.{h,m}",
    "exclude_files": "SPSlideTabBarControllerDemo",
    "public_header_files": "SPSlideTabBarController/SPSlideTabBarController/**/*.h",
    "requires_arc": true
}

Pin It on Pinterest

Share This