iOS自定义AlertView

在iOS开发中,我们经常会用到一些提示框或者一些弹出菜单,但是这些视图系统自带的视图是满足不了的,比如这种:

WechatIMG186.jpeg

再比如这种:
WechatIMG185.jpeg

这个时候就需要我们自定义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;

效果:


2019-03-21 12_47_59.gif

其他

GitHub地址

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容