PS:最近项目需要,微信样式的底部选择弹框,自定义的带有简单动画样式的弹窗以及多项选择功能.
最近将这三个需求进行了一下简单的封装,基本上两行代码就可以满足以上需求.
示例GIF

用法如下:
//微信样式底部弹窗示例代码如下:
- (IBAction)clickStyle1Button:(UIButton *)sender {
__weak typeof(self) weakSelf = self;
//选择数组
NSArray *dataArray = [NSArray arrayWithObjects:@"小视频", @"拍照",@"从手机相册选择",@"取消",nil];
CCPActionSheetView *actionSheetView = [[CCPActionSheetView alloc]initWithActionSheetArray:dataArray];
//点击完成后的回调
[actionSheetView cellDidSelectBlock:^(NSString *indexString, NSInteger index) {
weakSelf.selectedContentLabel.text = [NSString stringWithFormat:@"%ld----%@",(long)index,indexString];
}];
}
//带有动画效果的弹窗示例代码如下
- (IBAction)clickStyle2Button:(UIButton *)sender {
//自定义的弹窗view
UIImageView *testView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
testView.userInteractionEnabled = YES;
testView.image = [UIImage imageNamed:@"image0"];
CCPActionSheetView *alertview = [[CCPActionSheetView alloc] initWithAlertView:testView];
//动画样式
alertview.viewAnimateStyle = ViewAnimateScale;
}
//多项选择示例代码如下:
- (IBAction)clickMakeChoiceBtn:(UIButton *)sender {
//测试数据源数组
NSArray *dataArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21", nil];
//ClickSureBtnBlock —> 确定按钮的回调,将拼接好的字符串,以及选择成功的数组回调到当前VC
//ClickCancelBtnBlock —> 取消按钮的回调
CCPMultipleChoiceView *ChoiceView = [[CCPMultipleChoiceView alloc] initWithDataArr:dataArray andClickSureBtnBlock:^(NSString *combinedString, NSArray *backArray) {
self.choiceResultLabel.text = combinedString;
NSLog(@"%@",backArray);
} andClickCancelBtnBlock:^{
}];
//测试已经选中的数据源数组
如果不需要进入选择视图时显示已经选择的选项则 设置 ChoiceView.selectedArray = nil;
//如果需要进入选择视图时显示已经选择的选项 则设置已经选中的数据源数组
//@[@"1",@"3",@"10",@"0",@"20"]; 为对应的选中数据的下标
ChoiceView.selectedArray = @[@"1",@"3",@"10",@"0",@"20"];
}
希望在为你带来些许帮助的同时, star 一下该demo,感谢你的阅读.
网友评论