测试测试过 | ✗ |
语言语言 | Obj-CObjective C |
许可 | MIT |
发布最新版本 | 2015年10月 |
由 Klevison Matias 维护。
基于 Apples 的示例的 Accordion UITableViewController 组件。
Swift 版本: https://github.com/klevison/AccordionTableViewController
版本: 0.2
CocoaPods 是安装 KMAccordionTableViewController 的最简单方式。运行 pod search KMAccordionTableViewController
以搜索最新版本。然后,将 pod
行复制并粘贴到您的 Podfile
中。您的 podfile 应看起来像这样
platform :ios, '6.0'
pod 'KMAccordionTableViewController'
最后,通过运行 pod install
来安装它。
如果您不使用 CocoaPods,请将“Classes”目录下的所有文件导入到您的项目中。
#import "KMAccordionTableViewController.h"
@interface MyViewController : KMAccordionTableViewController
@end
- (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;
@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
#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];
}
如果您有任何问题、评论或建议,请给我发消息。如果您发现了一个错误,或想要提交一个 pull request,请让我知道。
版权(c)2014 Klevison Matias (http://twitter.com/klevison)。代码在 MIT 许可证下发布。