EMAccordionTableViewController 0.5.5

EMAccordionTableViewController 0.5.5

测试测试过的
语种语言 MUMPSMUMPS
许可证 自定义
发布最新发布2016年12月

Ennio Masi 维护。



alt tag

EMAccordionTableViewController 是一个易于使用的可展开/折叠的 UITableViewDataSource 用于 iOS。它底层实现为一个 UITableViewDataSource 的代理,将 tableView:cellForRowAtIndexPath 和 tableView:didSelectRowAtIndexPath 的责任留给了代理。

更新:现在它支持带有视差效果的表头视图。我使用了 wwdc2013 中的 UIImage+ImageEffects 来支持模糊效果。

  • 通用设计
  • 使用 ARC(自动引用计数)
  • 支持 iOS > 6.0
  • 支持旋转
  • 完全可重用的组件

使用此控制器的应用程序

如何安装?

源代码

或者您可以直接复制文件夹 EMAccordionTable 中包含的所有文件,然后开始使用它!

它是如何工作的?

EMAccordionTableViewController 类

@interface EMAccordionTableViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UIImage * closedSectionIcon;
@property (nonatomic, strong) UIImage * openedSectionIcon;
@property (nonatomic, strong) UITableView *tableView;

- (id) initWithTable:(UITableView *)tableView;

- (void) addAccordionSection: (EMAccordionSection *) section;
- (void) setDelegate: (NSObject <EMAccordionTableDelegate> *) delegate;

- (void) setHeaderHeight:(CGFloat)height;

@end

EMAccordionTableDelegate 协议

@protocol EMAccordionTableDelegate

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
  • (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  • (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; @end

如何使用它?

示例

    // Setup the EMAccordionTableViewController
    origin = 20.0f;
    if ([[UIDevice currentDevice].model hasPrefix:@"iPad"])
        origin = 100.0f;

    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(origin, origin, self.view.bounds.size.width - origin*2, self.view.bounds.size.height - origin*2) style:UITableViewStylePlain];
    [tableView setSectionHeaderHeight:kTableHeaderHeight];
    /*
     ... set here some other tableView properties ...
     */

    // Setup the EMAccordionTableViewController
    emTV = [[EMAccordionTableViewController alloc] initWithTable:tableView withAnimationType:EMAnimationTypeBounce];
    [emTV setDelegate:self];

    [emTV setClosedSectionIcon:[UIImage imageNamed:@"closedIcon"]];
    [emTV setOpenedSectionIcon:[UIImage imageNamed:@"openedIcon"]];

    // If you want to set the parallax header view
    emParallaxHeaderView = [[EMAccordionTableParallaxHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, tableView.bounds.size.width, 200.0f)];
    emParallaxHeaderView.headerImage = [UIImage imageNamed:@"naples"];
    emTV.parallaxHeaderView = emParallaxHeaderView;

    // Setup some test data
    dataSection01 = [[NSMutableArray alloc] initWithObjects:@"Dog", @"Cat", @"Pig", nil];
    dataSection02 = [[NSMutableArray alloc] initWithObjects:@"Federer", @"Nadal", nil];
    //

    // Section graphics
    UIColor *sectionsColor = [UIColor colorWithRed:62.0f/255.0f green:119.0f/255.0f blue:190.0f/255.0f alpha:1.0f];
    UIColor *sectionTitleColor = [UIColor whiteColor];
    UIFont *sectionTitleFont = [UIFont fontWithName:@"Futura" size:24.0f];

    // Add the sections to the controller
    EMAccordionSection *section01 = [[EMAccordionSection alloc] init];
    [section01 setBackgroundColor:sectionsColor];
    [section01 setItems:dataSection01];
    [section01 setTitle:@"Animals"];
    [section01 setTitleFont:sectionTitleFont];
    [section01 setTitleColor:sectionTitleColor];
    [emTV addAccordionSection:section01];

    EMAccordionSection *section02 = [[EMAccordionSection alloc] init];
    [section02 setBackgroundColor:sectionsColor];
    [section02 setItems:dataSection02];
    [section02 setTitle:@"Tennis players"];
    [section02 setTitleColor:sectionTitleColor];
    [section01 setTitleFont:sectionTitleFont];
    [emTV addAccordionSection:section02];

    EMAccordionSection *section03 = [[EMAccordionSection alloc] init];
    [section03 setBackgroundColor:sectionsColor];
    [section03 setTitle:@"Buh!"];
    [section03 setTitleColor:sectionTitleColor];
    [section01 setTitleFont:sectionTitleFont];
    [emTV addAccordionSection:section03];

    sections = [[NSArray alloc] initWithObjects:section01, section02, section03, nil];

    [self.view addSubview:emTV.tableView];

帮我改进它!

如何?仅自由地分叉该项目并改进它!

如果您想联系我:Twitter: ennioma. 邮箱: [email protected]