iOS自定义的模态提示对话框
基本思路:
1.创建一个和整个屏幕一样大小的UIView遮住屏幕,使其不能进行其他操作
注意:[self.view.window addSubview:vwFullScreenView]; 添加至应用的最上层。
2.在遮罩UIView上添加一个用作对话框的UIView,然后在对话框UIView上添加自己想要的视图。
3.关闭的时候可以直接使用遮罩UIView的tag进行移除。
-(void) _doClickShowModalDialog : (UIButton*) sender { NSLog(@"_doClickShowModalDialog"); UIView* vwFullScreenView = [[UIView alloc]init]; vwFullScreenView.tag=9999; vwFullScreenView.backgroundColor=[UIColor clearColor]; vwFullScreenView.frame=self.view.window.frame; [self.view.window addSubview:vwFullScreenView]; UIView* vwDialog = [[UIView alloc] init]; vwDialog.frame=CGRectMake(0, 0, 200, 200); vwDialog.backgroundColor=[UIColor whiteColor]; vwDialog.layer.borderColor=[UIColor blueColor].CGColor; vwDialog.layer.borderWidth=0.6; vwDialog.layer.cornerRadius=6; vwDialog.center=vwFullScreenView.center; [vwFullScreenView addSubview:vwDialog]; UIButton* btnClick = [UIButton buttonWithType:UIButtonTypeCustom]; [btnClick setTitle:@"Close" forState:UIControlStateNormal]; [btnClick setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; btnClick.frame=CGRectMake((vwDialog.frame.size.width-100)/2, (vwDialog.frame.size.height-30)/2, 100, 30); [btnClick addTarget:self action:@selector(_doClickCloseDialog:) forControlEvents:UIControlEventTouchUpInside]; [vwDialog addSubview:btnClick]; } -(void) _doClickCloseDialog : (UIButton*) sender { NSLog(@"_doClickCloseDialog"); [[self.view.window viewWithTag:9999]removeFromSuperview]; }