Giter VIP home page Giter VIP logo

kmaccordiontableviewcontroller's Introduction

KMAccordionTableViewController

Accordion UITableViewController component based on Apples's example.

Swift version: https://github.com/klevison/AccordionTableViewController

...

Current Version

Version: 0.2.1

Under the Hood

  • iOS8 compatible
  • StoryBoad compatible
  • Supports customization
  • Supports UIViews as sections (UIViews, UIViewController's view, UITableViews, UIWebView, MKMapView, etc...)
  • Update content and size of a section
  • Custom animation

How to install it?

CocoaPods is the easiest way to install KMAccordionTableViewController. Run pod search KMAccordionTableViewController to search for the latest version. Then, copy and paste the pod line to your Podfile. Your podfile should look like:

platform :ios, '6.0'
pod 'KMAccordionTableViewController'

Finally, install it by running pod install.

If you don't use CocoaPods, import the all files from "Classes" directory to your project.

How to use it?

Extends from KMAccordionTableViewController

#import "KMAccordionTableViewController.h"

@interface MyViewController : KMAccordionTableViewController

@end

Implement KMAccordionTableViewControllerDataSource

- (NSInteger)numberOfSectionsInAccordionTableViewController:(KMAccordionTableViewController *)accordionTableView;

- (KMSection *)accordionTableView:(KMAccordionTableViewController *)accordionTableView sectionForRowAtIndex:(NSInteger)index;

- (CGFloat)accordionTableView:(KMAccordionTableViewController *)accordionTableView heightForSectionAtIndex:(NSInteger)index;

- (UITableViewRowAnimation)accordionTableViewOpenAnimation:(KMAccordionTableViewController *)accordionTableView;

- (UITableViewRowAnimation)accordionTableViewCloseAnimation:(KMAccordionTableViewController *)accordionTableView;

Customization

@property(nonatomic, assign) NSInteger headerHeight; //Sets section header height.
@property(nonatomic, strong) UIFont *headerFont; //Sets section header font.
@property(nonatomic, strong) UIColor *headerTitleColor; //Sets section header font color.
@property(nonatomic, strong) UIColor *headerColor; //Sets section header background color.
@property(nonatomic, strong) UIColor *headerSeparatorColor; //Sets section header separator color.
@property(nonatomic) UIImage *headerArrowImageOpened; //Sets section header disclosure opened image.
@property(nonatomic) UIImage *headerArrowImageClosed; //Sets section header disclosure closed image.

- (void)setOneSectionAlwaysOpen:(BOOL)isOpen; //set if one section should always be open. if set to YES, the VC will load with the first section already open, and the open section will not close unless you click a different section

Example

#import "MyViewController.h"

@interface MyViewController () <KMAccordionTableViewControllerDataSource>

@property NSArray *sections;

@end

@implementation MyViewController

- (NSInteger)numberOfSectionsInAccordionTableViewController:(KMAccordionTableViewController *)accordionTableView {
    return [self.sections count];
}

- (KMSection *)accordionTableView:(KMAccordionTableViewController *)accordionTableView sectionForRowAtIndex:(NSInteger)index {
    return self.sections[index];
}

- (CGFloat)accordionTableView:(KMAccordionTableViewController *)accordionTableView heightForSectionAtIndex:(NSInteger)index{
    KMSection *section = self.sections[index];
    return section.view.frame.size.height;
}

- (UITableViewRowAnimation)accordionTableViewOpenAnimation:(KMAccordionTableViewController *)accordionTableView
{
    return UITableViewRowAnimationFade;
}

- (UITableViewRowAnimation)accordionTableViewCloseAnimation:(KMAccordionTableViewController *)accordionTableView
{
    return UITableViewRowAnimationFade;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupAppearence];
    self.dataSource = self;
    self.sections = [self getSectionArray];
}

- (void)setupAppearence {
    [self setHeaderHeight:38];
    [self setHeaderArrowImageClosed:[UIImage imageNamed:@"carat-open"]];
    [self setHeaderArrowImageOpened:[UIImage imageNamed:@"carat"]];
    [self setHeaderFont:[UIFont fontWithName:@"HelveticaNeue" size:15]];
    [self setHeaderTitleColor:[UIColor greenColor]];
    [self setHeaderSeparatorColor:[UIColor colorWithRed:0.157 green:0.157 blue:0.157 alpha:1]];
    [self setHeaderColor:[UIColor colorWithRed:0.114 green:0.114 blue:0.114 alpha:1]];
    [self setOneSectionAlwaysOpen:NO];
}

- (NSArray *)getSectionArray {
    UIView *viewOfSection1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    KMSection *section1 = [KMSection alloc new];
    section1.view = viewOfSection1;
    section1.title = @"My First Section";

    UIView *viewOfSection2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
    KMSection *section2 = [KMSection alloc new];
    section2.view = viewOfSection2;
    section2.title = @"Sec. Section";

    UIView *viewOfSection3 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 700)];
    KMSection *section3 = [KMSection alloc new];
    section3.view = viewOfSection3;
    section3.title = @"thirddddd";

    return @[section1, section2, section3];
}

Contact

If you have any questions comments or suggestions, send me a message. If you find a bug, or want to submit a pull request, let me know.

Copyright and license

Copyright (c) 2014 Klevison Matias (http://twitter.com/klevison). Code released under the MIT license.

kmaccordiontableviewcontroller's People

Contributors

klevison avatar danielpassos avatar jairobjunior avatar vfmneto avatar

Watchers

Hamad Deshmukh 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.