首页 > IT职业 > IT职场 > iOS学习笔记--PresentedVC自定义弹窗

我选择这种方法的原因是简单方便,有复杂交互的也可以,那就是两个控制器之间的传值了。
这里上代码:
#import "BCAlertViewController.h"
@interface BCAlertViewController ()
@property (weak, nonatomic) IBOutlet UIView *alertView0;
@property (weak, nonatomic) IBOutlet UILabel *textContent;
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
@end
@implementation BCAlertViewController
- (void)viewDidLoad {
[super viewDidLoad];
//标注方法setCornerRadious:4 borderColor:nil borderWidth:0 ①
[self.alertView0 setCornerRadious:4 borderColor:nil borderWidth:0];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (IBAction)closeBtnClicked:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self dismissViewControllerAnimated:YES completion:nil];
}
@end //方法①的注释 自己写Category
#import "UIView+CornerRadious.h"
@implementation UIView (CornerRadious)
//设置圆角
- (void)setCornerRadious:(CGFloat)cornerRadious borderColor:(UIColor *)borderColor borderWidth:(CGFloat)borderWidth
{
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:cornerRadious];
CAShapeLayer *maskLayer= [[CAShapeLayer alloc]init];
maskLayer.frame = self.bounds;
maskLayer.path = path.CGPath;
CAShapeLayer *borderLayer = [[CAShapeLayer alloc]init];
borderLayer.lineWidth = borderWidth;
borderLayer.strokeColor = borderColor.CGColor;
borderLayer.fillColor = ClearColor.CGColor;
borderLayer.frame = self.bounds;
borderLayer.path = path.CGPath;
[self.layer insertSublayer:borderLayer atIndex:0];
self.layer.mask = maskLayer;
} ///使用方法
- (IBAction)registerBtnClicked:(id)sender {
BCAlertViewController *alert = [[BCAlertViewController alloc]init];
alert.modalPresentationStyle = UIModalPresentationOverCurrentContext;
alert.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self.navigationController presentViewController:alert animated:YES completion:nil];
} 注意:BCAlertViewController.h 的view的背景色设置
[[UIColor blackColor]colorWithAlphaComponent:0.2]; 来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/855/viewspace-2799745/ ,如需转载,请注明出处,否则将追究法律责任。