Giter Site home page Giter Site logo

dixit7405 / spslidetabbarcontroller Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aokizen/spslidetabbarcontroller

0.0 1.0 0.0 4.01 MB

A TabBarController with top TabBar and slide content view for iOS.

License: MIT License

Ruby 8.88% Objective-C 91.12%

spslidetabbarcontroller's Introduction

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;
  1. 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
  1. 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];
            [button setTag:tag];
            [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.scrollView addSubview:button];
        }
    
        /**
         * style the button
         */
        if (item.attibutedTitle) {
            [button setAttributedTitle:item.attibutedTitle forState:UIControlStateNormal];
        }
        else {
            [button setTitle:item.title forState:UIControlStateNormal];
            [button.titleLabel setFont:item.barItemTextFont];
            [button setTitleColor:item.barItemTextColor forState:UIControlStateNormal];
            [button setTitleColor:item.barItemSelectedTextColor forState:UIControlStateHighlighted];
            [button setTitleColor:item.barItemSelectedTextColor forState:UIControlStateSelected];
            [button setTitleColor:item.barItemSelectedTextColor forState:UIControlStateSelected | UIControlStateHighlighted];
        }
    
        [button setSelected:(index == self.selectedTabIndex)];
    }];

License

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

spslidetabbarcontroller's People

Contributors

aokizen avatar munirwanis avatar

Watchers

 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.