一:实现效果
二:实现方法
1:调用方法
NSLog(@"点击弹出框");
// 注意:由convertRect: toView 获取到屏幕上该控件的绝对位置。
UIWindow *window = [[UIApplication sharedApplication].delegate window];
CGRect frame = [optionButton convertRect:optionButton.bounds toView:window];
OYRPopOption *s = [[OYRPopOption alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, IPHONE_HEIGHT)];
s.option_optionContents = @[@"退出", @"分享", @"邀请好友"];
s.option_optionImages = @[@"icon_quit_matchdetail",@"icon_nav_share",@"icon_invite_matchdetail"];
// 使用链式语法直接展示 无需再写 [s option_show];
[[s option_setupPopOption:^(NSInteger index, NSString *content) {
NSLog(@"你选中了第%ld行选项为:%@", (long)index, content);
NSString *popStr = [NSString stringWithFormat:@"你选中了第%ld行选项为:%@", (long)index, content];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:popStr preferredStyle:UIAlertControllerStyleAlert];
//添加的输入框
//WS(weakSelf);
UIAlertAction *Action = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *twoAc = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//添加的带输入框的提示框
}];
[alert addAction:Action];
[alert addAction:twoAc];
[self presentViewController:alert animated:YES completion:nil];
if (index == 0) {
}else if (index == 1){
}else if (index == 2){
}
} whichFrame:frame animate:YES] option_show];
二:自定义弹出框
typedef void(^OYRPopOptionBlock)(NSInteger index, NSString *content);
@interface OYRPopOption : UIView
@property (nonatomic, strong) NSArray *option_optionContents; // 内容数组 必要
@property (nonatomic, strong) NSArray *option_optionImages; // 图片数组 非必要
@property (nonatomic, assign) CGFloat option_lineHeight; // 行高 如果不设置默认为40.0f
@property (nonatomic, assign) CGFloat option_mutiple; // 宽度比 如果不设置默认为0.35f
@property (nonatomic ,assign) float option_animateTime; // 设置动画时长 如果不设置默认0.2f秒 如果设置为0为没有动画
// 加载pop框
// block 你选中的选项
// 是否有动画
- (instancetype) option_setupPopOption:(OYRPopOptionBlock)block whichFrame:(CGRect)frame animate:(BOOL)animate;
/** 展示Pop 推荐使用链式语法 */
- (void) option_show;
github地址:https://github.com/ouyangrong1313/OYRPopOptionViewgithub地址