iOS 彈出的選擇框,類似微信掃碼彈出框

一:實(shí)現(xiàn)效果


二:實(shí)現(xiàn)方法

1:調(diào)用方法

NSLog(@"點(diǎn)擊彈出框");

// 注意:由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"];

// 使用鏈?zhǔn)秸Z法直接展示 無需再寫 [s option_show];

[[s option_setupPopOption:^(NSInteger index, NSString *content) {

NSLog(@"你選中了第%ld行選項(xiàng)為:%@", (long)index, content);

NSString *popStr = [NSString stringWithFormat:@"你選中了第%ld行選項(xiàng)為:%@", (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;? // 內(nèi)容數(shù)組 必要

@property (nonatomic, strong) NSArray *option_optionImages;? ? // 圖片數(shù)組 非必要

@property (nonatomic, assign) CGFloat? option_lineHeight;? ? ? // 行高? 如果不設(shè)置默認(rèn)為40.0f

@property (nonatomic, assign) CGFloat? option_mutiple;? ? ? ? ? // 寬度比 如果不設(shè)置默認(rèn)為0.35f

@property (nonatomic ,assign) float? ? option_animateTime;? ? ? // 設(shè)置動畫時長 如果不設(shè)置默認(rèn)0.2f秒 如果設(shè)置為0為沒有動畫

// 加載pop框

// block 你選中的選項(xiàng)

// 是否有動畫

- (instancetype) option_setupPopOption:(OYRPopOptionBlock)block whichFrame:(CGRect)frame animate:(BOOL)animate;

/** 展示Pop 推薦使用鏈?zhǔn)秸Z法 */

- (void) option_show;

github地址:https://github.com/ouyangrong1313/OYRPopOptionViewgithub地址

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容