有时候我们想做一个,类似于UIActionSheet的东西,而UIActionSheet又不能满足我们,那么我们就可以用JGActionSheet来实现。
JGActionSheetSection的下载URL:
http://code4app.com/ios/JGActionSheet/53f31014933bf02c718b550b
要使用JGActionSheet就要引用JGActionSheet.h文件
JGActionSheetSection的思路是:
sheet,是全部的框体,一个sheet里面,包含很多个section,每个section下呢,又包含很多button,所以当用sheet.sections取值的时候,实际上取出的是一个数组,section.buttons也是同理。
代码:
//初始化一个section
//初始化的section的title是section title,在标题底下的方位会显示message,内容是message under title,buttonTitles参数是一个数组参数,里面是这个section里面的button的名字,buttonStyle参数是button的样式,这个样式也可以自己定义
JGActionSheetSection *section = [JGActionSheetSection sectionWithTitle:@"section title" message:@"message under title" buttonTitles:@[@"button1",@"button2"] buttonStyle:JGActionSheetButtonStyleDefault];
//初始化sheet,需要传入一开始初始化的section,是一个数组参数
JGActionSheet *sheet = [JGActionSheetactionSheetWithSections:@[section]];
//设置dletegate
sheet.delegate = self;
//sheet悬停的设置
sheet.insets = UIEdgeInsetsMake(20.0f, 0.0f, 0.0f, 0.0f);
//显示这个sheet
[sheet showInView:self.XXXXXXX.viewanimated:YES];
//点击里面任意button的回调事件
[sheet setButtonPressedBlock:^(JGActionSheet *sheet, NSIndexPath *indexPath) {
//取得点击的button在哪个section(indexPath.section是section的下标)
JGActionSheetSection *JGS = (JGActionSheetSection *)sheet.sections[indexPath.section];
//取得点击的那个button(indexPath.row是section里面button的下标)
UIButton *btn = JGS.buttons[indexPath.row];
//关闭悬浮框
[sheet dismissAnimated:YES];
XXXXXXXXXXXXX;
}