在iOS开发中,我们经常会用到一些
提示框
或者一些弹出菜单
,但是这些视图系统自带的视图是满足不了的,比如这种:
再比如这种:
这个时候就需要我们自定义AlertView:
下边CenterAlertContentView是自定义contentView
// 从中间弹出
- (IBAction)centerAlertAction:(id)sender {
NKAlertView *alertView = [[NKAlertView alloc] init];
CenterAlertContentView *customContentView = [[CenterAlertContentView alloc] initWithFrame:CGRectMake(0, 0, 281, 281)];
alertView.contentView = customContentView;
// 点击背景隐藏提示框
alertView.hiddenWhenTapBG = YES;
[alertView show];
}
从底部弹出时添加圆角:
/*
利用贝塞尔曲线为contentView的左上角、右上角设置圆角;
如果不需要可以注释下边代码
*/
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:_contentView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = _contentView.bounds;
shapeLayer.path = path.CGPath;
_contentView.layer.mask = shapeLayer;
效果: