1.首先自定义一个UIView 用来作为SectionHeader,用一个大的button覆盖整个View
MKAccordionButton.h文件
#import <UIKit/UIKit.h>
@interface MKAccordionButton : UIView
@property (nonatomic,weak) IBOutlet UIButton *mainButton;
// 返回值 快名称 参数
@property (nonatomic,copy) void(^buttonTappedHandler)();
@end
MKAccordionButton.m文件
这里,需要注意的就是使用button的点击事件来调用块
#import "MKAccordionButton.h"
@implementation MKAccordionButton
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)awakeFromNib{
//样式设置
self.layer.borderColor = [UIColor colorWithWhite:0.6 alpha:0.6].CGColor;
self.layer.borderWidth = 1.0f;
[super awakeFromNib];
}
- (IBAction)buttonTapped:(id)sender
{
//如果块不为nil,则调用块
if(self.buttonTappedHandler)
self.buttonTappedHandler();
}
@end