弹窗控件:LXAlertView,可定制化大多数弹窗

LXAlertView.h文件

//
// LXAlertView.h
// test
//
// Created by 天边的星星 on 2019/6/14.
// Copyright © 2019 starxin. All rights reserved.
//

#import 

///@summary 按钮排列方式,默认是水平排列
typedef NS_ENUM(uint, LXAlertViewButtonQueueType) {
    ///水平排序
    LXAlertViewButtonQueueTypeHorizonal = 0,
    ///垂直排序
    LXAlertViewButtonQueueTypeVertical
};
///@summary 关闭按钮的方向
typedef NS_ENUM(uint, LXAlertViewCloseDirectionType) {
    ///左上
    LXAlertViewCloseDirectionTypeLeft = 0,
    ///右上
    LXAlertViewCloseDirectionTypeRight
};
/**
 @summary 内部事件回调类型

 - LXAlertViewEventTypeMask: 蒙版点击事件
 - LXAlertViewEventTypeClose: 按钮关闭事件
 - LXAlertViewEventTypeButtons: 底部按钮事件
 - LXAlertViewEventTypeTextView: UITextView富文本内部事件:url链接和attachment事件
 */
typedef NS_ENUM(int, LXAlertViewEventType) {
    ///蒙版点击事件
    LXAlertViewEventTypeMask = -1,
    ///按钮关闭事件
    LXAlertViewEventTypeClose,
    ///底部按钮事件
    LXAlertViewEventTypeButtons,
    ///UITextView富文本内部事件:url链接和attachment事件
    LXAlertViewEventTypeTextView
};


/**
 弹窗界面事件回调,idx和obj的优先级比较:obj优先级大于idx,若
 
 @param idx -1:点击了蒙版回调,必须设置allowMaskCallback=YES才有回调,关闭按钮回调是0,其它按钮的从左到右或者从上到下的顺序从1递增
 */

/**
 弹窗界面事件回调

 @param eventType 内部事件类型,详情请查看LXAlertViewEventType定义
 @param obj 只在LXAlertViewEventTypeButtons和LXAlertViewEventTypeTextView事件类型下有效,用于区分具体事件对象,LXAlertViewEventTypeButtons下为按钮的索引对象,LXAlertViewEventTypeTextView为NSURL或者NSTextAttachment对象
 @param text 仅在textViewAllowInput=yes时才有值
 */
typedef void (^LXAlertEventBlock)(LXAlertViewEventType eventType, id __nullable obj, NSString* __nullable text);

NS_ASSUME_NONNULL_BEGIN

/**
 @summary 同系统UIAlertView的弹窗控件,此控件只是创建弹窗控件,相关显示动效需要自己去定制
 @detail 内部控件从上往下依次是:图片、文本、子文本、text view、按钮,根据设置动态计算size和origin,alertView的高度是动态计算的,顶部关闭按钮
 */
@interface LXAlertView : UIView

#pragma mark --- 全局设置
///alert view的宽度,默认是260
@property (nonatomic, assign, readwrite) CGFloat alertViewWidth;

#pragma mark --- 顶部关闭按钮
///顶部关闭按钮的图片名称,没有就不显示
@property (nonatomic, copy, readwrite) NSString* closeImgName;

///顶部按钮的方向,默认是LXAlertViewCloseDirectionTypeRight
@property (nonatomic, assign) LXAlertViewCloseDirectionType closeDirection;

///顶部按钮的size,若未设置则根据图片实际大小
@property (nonatomic, assign) CGSize closeSize;

#pragma mark --- 蒙版设置
///蒙版颜色,默认是黑色,alpha为0.3;
@property (nonatomic, strong) UIColor* maskBackgroundColor;

#pragma mark --- 图片属性设置
///图片名称,以图片有二进制数据为创建图片控件的依据
@property (nonatomic, copy, readwrite) NSString* imgName;

///图片宽度,默认值图片的实际宽度
@property (nonatomic, assign, readwrite) CGFloat imgWidth;

///图片高度,默认值图片的实际高度
@property (nonatomic, assign, readwrite) CGFloat imgHeight;

///图片显示模式,默认UIViewContentModeScaleAspectFit
@property (nonatomic, assign, readwrite) UIViewContentMode imgContentMode;

///图片的背景颜色,默认是无色
@property (nonatomic, strong, readwrite) UIColor* imgBackgroundColor;

#pragma mark --- 文本属性设置
///文本内容,若同时设置了富文本,则富文本优先级高,富文本下文本内容的其他属性设置无效
@property (nonatomic, copy, readwrite) NSString* text;

///文本富文本,不为空才会创建文本控件
@property (nonatomic, copy, readwrite) NSAttributedString* attText;

///文本字体大小,默认系统16,富文本无效
@property (nonatomic, strong, readwrite) UIFont* textFont;

///文本颜色,默认系统darkTextColor,富文本无效
@property (nonatomic, strong, readwrite) UIColor* textColor;

///文本的背景颜色
@property (nonatomic, strong, readwrite) UIColor* textBackgroundColor;

///文本对齐方式,默认是center,富文本无效
@property (nonatomic, assign) NSTextAlignment textAlignment;


///子文本内容,若同时设置了富文本,则富文本优先级高,富文本下文本内容的其他属性设置无效
@property (nonatomic, copy, readwrite) NSString* subText;

///子文本富文本,不为空才会创建子文本控件
@property (nonatomic, copy, readwrite) NSAttributedString* subAttText;

///子文本字体大小,默认系统15,富文本无效
@property (nonatomic, strong, readwrite) UIFont* subTextFont;

///子文本颜色默认系统darkTextColor,富文本无效
@property (nonatomic, strong, readwrite) UIColor* subTextColor;

///子文本的背景颜色
@property (nonatomic, strong, readwrite) UIColor* subTextBackgroundColor;

///子文本对齐方式,默认是center,富文本无效
@property (nonatomic, assign) NSTextAlignment subTextAlignment;

#pragma mark --- text view属性设置
///是否允许输入文本,若允许输入则高度为外界传入的textViewHeight高度,若不允许输入则为实际内容的高度,不可编辑内容不可滚动,并可回调内部url链接点击事件,默认是NO
@property (nonatomic, assign, readwrite) BOOL textViewAllowInput;

///text view的文本内容,富文本下无效
@property (nonatomic, copy, readwrite) NSString* textViewText;

///text view的富文本
@property (nonatomic, copy, readwrite) NSAttributedString* textViewAttText;

///text view的颜色,富文本无效,默认系统darkTextColor
@property (nonatomic, strong, readwrite) UIColor* textViewTextColor;

///text view的文本字体大小,默认系统15,富文本无效
@property (nonatomic, strong, readwrite) UIFont* textViewTextFont;

///text view的背景颜色,默认是白色
@property (nonatomic, strong, readwrite) UIColor* textViewBackgroundColor;

///text view的高度,默认值为50
@property (nonatomic, assign, readwrite) CGFloat textViewHeight;

///text view的border color
@property (nonatomic, strong, readwrite) UIColor* textViewBorderColor;

///text view的border width
@property (nonatomic, assign, readwrite) CGFloat textViewBorderWidth;

///text view的corner radius
@property (nonatomic, assign, readwrite) CGFloat textViewCornerRadius;

#pragma mark --- 按钮属性设置,注意按钮的宽度是根据间距和父控件宽度动态计算的
///按钮的标题数组,数组个数不等于0才会创建按钮控件
@property (nonatomic, strong, readwrite) NSArray* btnTitlesArr;

///按钮的标题颜色,默认0x222222
@property (nonatomic, strong, readwrite) NSArray* btnColorsArr;

///按钮的标题字体大小,默认系统15
@property (nonatomic, strong, readwrite) NSArray* btnFontsArr;

///按钮的border宽度
@property (nonatomic, strong, readwrite) NSArray* btnBorderWidthArr;

///按钮的border颜色
@property (nonatomic, strong, readwrite) NSArray* btnBorderColorArr;

///按钮的corner radius
@property (nonatomic, strong, readwrite) NSArray* btnCornerRadiusArr;

///按钮背景颜色
@property (nonatomic, strong, readwrite) NSArray* btnBackgroundColorsArr;

///按钮高度,默认是44
@property (nonatomic, assign, readwrite) CGFloat btnHeight;

///按钮排序方式,默认是LXAlertViewButtonQueueTypeHorizonal
@property (nonatomic, assign, readwrite) LXAlertViewButtonQueueType queueType;

#pragma mark --- 间距设置
///alert view的子控件的初始y值,默认是16
@property (nonatomic, assign, readwrite) CGFloat originY;

///alert view的中心点距离父控件的中心点偏移量,默认是0
@property (nonatomic, assign, readwrite) CGFloat marginCenterY;

///图片和文本垂直方向的间距,默认值为20
@property (nonatomic, assign, readwrite) CGFloat marginBetweenImageAndText;

///文本和子文本垂直方向的间距,默认值为20
@property (nonatomic, assign, readwrite) CGFloat marginBetweenTextAndSubText;

///子文本和text view的垂直方向的间距,默认值20
@property (nonatomic, assign, readwrite) CGFloat marginBetweenSubTextAndTextView;

///text view和按钮垂直方向的间距,默认值为20
@property (nonatomic, assign, readwrite) CGFloat marginBetweenTextViewAndButton;

///文本距离父控件左边距,默认值为40
@property (nonatomic, assign, readwrite) CGFloat marginLeftXText;

///文本距离父控件右边距,默认值为40
@property (nonatomic, assign, readwrite) CGFloat marginRightXText;

///子文本距离父控件左边距,默认值为40
@property (nonatomic, assign, readwrite) CGFloat marginLeftXSubText;

///子文本距离父控件右边距,默认值为40
@property (nonatomic, assign, readwrite) CGFloat marginRightXSubText;

///text view距离父控件左边距,默认值为40
@property (nonatomic, assign, readwrite) CGFloat marginLeftXTextView;

///text view距离父控件右边距,默认值为40
@property (nonatomic, assign, readwrite) CGFloat marginRightXTextView;

///最左边按钮距离父控件左边距,默认值为40
@property (nonatomic, assign, readwrite) CGFloat marginLeftXLeftButton;

///最右边按钮距离父控件右边距,默认值为40
@property (nonatomic, assign, readwrite) CGFloat marginRightXRightButton;

///按钮之间的间距,默认是20,当queueType=LXAlertViewButtonQueueTypeHorizonal时,此间距
///为水平按钮之间间距;当queueType=LXAlertViewButtonQueueTypeVertical时,此间距为垂直按钮之间的间距
@property (nonatomic, assign, readwrite) CGFloat marginBetweenButtons;

///按钮底部距离alert view的垂直方向的间距,默认值为16
@property (nonatomic, assign, readwrite) CGFloat marginButtonBottom;

///顶部关闭按钮的水平间距,默认是0,若方向为LXAlertViewCloseDirectionTypeLeft则为左边距,LXAlertViewCloseDirectionTypeRight则为右边距
@property (nonatomic, assign, readwrite) CGFloat marginCloseHoriznal;

///顶部关闭按钮垂直间距,默认是0
@property (nonatomic, assign, readwrite) CGFloat marginCloseVertical;

#pragma mark --- 回调设置
///是否允许点击蒙版回调回调,默认是NO
@property (nonatomic, assign, getter=isAllowMaskCallback) BOOL allowMaskCallback;
///内部事件回调:allowMaskCallback=yes时,点击蒙版才会回调
@property (nonatomic, copy) LXAlertEventBlock alertEventBlock;
///是否自动隐藏,内部事件触发时,默认是yes
@property (nonatomic, assign, getter=isAutoHide) BOOL autoHideWhenEvent;

#pragma mark --- actions
///内部蒙版控件共享给外部获取,方便做一些动画之类的操作
@property (nonatomic, strong, readonly) UIView* maskBackView;
///移除控件
- (void)remove;

@end

NS_ASSUME_NONNULL_END

LXAlertView.m文件

//
//  LXAlertView.m
//  test
//
//  Created by 天边的星星 on 2019/6/14.
//  Copyright © 2019 starxin. All rights reserved.
//

#import "LXAlertView.h"

#define kLQHexColor(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0f green:((c>>8)&0xFF)/255.0f blue:(c&0xFF)/255.0f alpha:1.0f]

@interface LXAlertView ()

@property (nonatomic, strong, readonly) UIButton* closeBtn;
@property (nonatomic, strong, readonly) UIImageView* imgView;
@property (nonatomic, strong, readonly) UILabel* textLbl;
@property (nonatomic, strong, readonly) UILabel* subTextLbl;
@property (nonatomic, strong, readonly) UITextView* textView;
@property (nonatomic, strong, readonly) NSMutableArray* buttonArrM;

///父控件
@property (nonatomic, weak) UIView* parentView;

@end

@implementation LXAlertView

#pragma mark --- life cycle

- (instancetype)init {
    if (self = [super init]) {
        [self p_initConfiguration];
    }
    return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self p_initConfiguration];
    }
    return self;
}
- (void)p_initConfiguration {
    _buttonArrM = [NSMutableArray array];
    
    if (self.frame.size.width < 1.0) {
        _alertViewWidth = 260;
    }
    self.backgroundColor = UIColor.whiteColor;
    _alertViewWidth = 260;
    _closeDirection = LXAlertViewCloseDirectionTypeRight;
    _closeSize = CGSizeZero;
    
    _maskBackgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.3];
    
    _imgContentMode = UIViewContentModeScaleAspectFit;
    
    _textFont = [UIFont systemFontOfSize:16];
    _textColor = UIColor.darkTextColor;
    _textAlignment = NSTextAlignmentCenter;
    
    _subTextFont = [UIFont systemFontOfSize:15];
    _subTextColor = UIColor.darkTextColor;
    _subTextAlignment = NSTextAlignmentCenter;
    
    _textViewTextColor = UIColor.darkTextColor;
    _textViewTextFont = [UIFont systemFontOfSize:15];
    _textViewBackgroundColor = UIColor.whiteColor;
    _textViewHeight = 50;
    
    _btnHeight = 44;
    _queueType = LXAlertViewButtonQueueTypeHorizonal;
    
    _originY = 16;
    _marginCenterY = 0;
    _marginBetweenImageAndText = 20;
    _marginBetweenTextAndSubText = 20;
    _marginBetweenSubTextAndTextView = 20;
    _marginBetweenTextViewAndButton = 20;
    _marginLeftXText = 40;
    _marginRightXText = 40;
    _marginLeftXSubText = 40;
    _marginRightXSubText = 40;
    _marginLeftXTextView = 40;
    _marginRightXTextView = 40;
    _marginLeftXLeftButton = 40;
    _marginRightXRightButton = 40;
    _marginBetweenButtons = 20;
    _marginButtonBottom = 16;
    
    _marginCloseHoriznal = 0;
    _marginCloseVertical = 0;
    _autoHideWhenEvent = YES;
}
- (void)willMoveToSuperview:(UIView *)newSuperview {
    if (newSuperview) {
        _parentView = newSuperview;
        self.frame = CGRectMake((newSuperview.frame.size.width-_alertViewWidth)*0.5, 0, _alertViewWidth, 0);
        [self p_setupView];
    }
}
- (void)p_setupView {
    
    _maskBackView = UIView.alloc.init;
    _maskBackView.backgroundColor = _maskBackgroundColor;
    _maskBackView.frame = self.parentView.bounds;
    if (_allowMaskCallback) {
        UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(p_actionForClickMaskView)];
        [_maskBackView addGestureRecognizer:tap];
    }
    [self.parentView addSubview:_maskBackView];
    
    if (_closeImgName) {
        UIImage* img = [UIImage imageNamed:_closeImgName];
        if (img) {
            _closeBtn = UIButton.alloc.init;
            _closeBtn.contentMode = UIViewContentModeScaleAspectFit;
            [_closeBtn setImage:img forState:UIControlStateNormal];
            if (CGSizeEqualToSize(CGSizeZero, _closeSize)) {
                _closeSize = img.size;
            }
            if (_closeDirection == LXAlertViewCloseDirectionTypeLeft) {
                _closeBtn.frame = CGRectMake(_marginCloseHoriznal, _marginCloseVertical, _closeSize.width, _closeSize.height);
            }else {
                _closeBtn.frame = CGRectMake(_alertViewWidth-_marginCloseHoriznal-_closeSize.width, _marginCloseVertical, _closeSize.width, _closeSize.height);
            }
            [_closeBtn addTarget:self action:@selector(p_actionForCloseButton:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:_closeBtn];
        }
    }
    
    
    _imgView = UIImageView.alloc.init;
    _imgView.backgroundColor = _imgBackgroundColor;
    _imgView.contentMode = _imgContentMode;
    
    _textLbl = UILabel.alloc.init;
    _textLbl.numberOfLines = 0;
    _textLbl.textAlignment = _textAlignment;
    _textLbl.backgroundColor = _textBackgroundColor;
    _textLbl.preferredMaxLayoutWidth = self.frame.size.width-_marginLeftXText-_marginRightXText;
    _textLbl.frame = CGRectMake(0, 0, _textLbl.preferredMaxLayoutWidth, 0);
    
    _subTextLbl = UILabel.alloc.init;
    _subTextLbl.numberOfLines = 0;
    _subTextLbl.textAlignment = _subTextAlignment;
    _subTextLbl.backgroundColor = _subTextBackgroundColor;
    _subTextLbl.preferredMaxLayoutWidth = self.frame.size.width-_marginLeftXSubText-_marginRightXSubText;
    _subTextLbl.frame = CGRectMake(0, 0, _subTextLbl.preferredMaxLayoutWidth, 0);
    
    _textView = UITextView.alloc.init;
    _textView.backgroundColor = _textViewBackgroundColor;
    _textView.layer.borderColor = _textViewBorderColor.CGColor;
    _textView.layer.borderWidth = _textViewBorderWidth;
    _textView.layer.cornerRadius = _textViewCornerRadius;
    _textView.font = _textViewTextFont;
    _textView.textColor = _textViewTextColor;
    _textView.editable = _textViewAllowInput;
    _textView.scrollEnabled = _textViewAllowInput;
    
    [self addSubview:self.imgView];
    [self addSubview:self.textLbl];
    [self addSubview:self.subTextLbl];
    [self addSubview:self.textView];
    
    //图片处理
    [self p_actionForInitImgView];
    
    //文本处理
    [self p_actionForInitTextLabel];
    
    //子文本处理
    [self p_actionForInitSubTextLabel];
    
    //text view处理
    [self p_actionForInitTextView];
    
    //按钮处理
    [self p_actionForInitButtons];
    
    //计算所有控件的有效高度
    [self p_actionForUpdateOrigin];
}

#pragma mark --- actions
- (void)setTextViewAllowInput:(BOOL)textViewAllowInput {
    _textViewAllowInput = textViewAllowInput;
    if (textViewAllowInput) {
        [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(p_actionForWillShowKeyboard:) name:UIKeyboardWillShowNotification object:nil];
        [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(p_actionForWillHideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
    }
}
- (void)p_actionForWillShowKeyboard:(NSNotification *)noti {
    CGFloat endKeyboardY = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue].origin.y;
    NSInteger curve = [noti.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
    CGFloat duration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    
    //需要上移多少
    CGFloat marginMoveUp = 0;
    //转换坐标
    UIWindow* keyWindow = UIApplication.sharedApplication.delegate.window;
    CGPoint keyPoint = [self convertPoint:CGPointMake(0, self.frame.size.height) toView:keyWindow];
    if (keyPoint.y > endKeyboardY) {//需要上移
        marginMoveUp = keyPoint.y-endKeyboardY;
    }
    
    [UIView animateWithDuration:duration delay:0 options:curve animations:^{
        self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y-marginMoveUp, self.frame.size.width, self.frame.size.height);
    } completion:nil];
}
- (void)p_actionForWillHideKeyboard:(NSNotification *)noti {
    NSInteger curve = [noti.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
    CGFloat duration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    [UIView animateWithDuration:duration delay:0 options:curve animations:^{
        self.frame = CGRectMake(self.frame.origin.x, (self.parentView.frame.size.height-self.frame.size.height)*0.5+self.marginCenterY, self.frame.size.width, self.frame.size.height);
    } completion:nil];
}
///图片处理,主要是设置图片的宽高
- (void)p_actionForInitImgView {
    if (_imgName) {
        UIImage* img = [UIImage imageNamed:_imgName];
        if (img) {
            if (_imgWidth < 1) {
                _imgWidth = img.size.width;
            }
            if (_imgHeight < 1) {
                _imgHeight = img.size.height;
            }
            _imgView.frame = CGRectMake(0, 0, _imgWidth, _imgHeight);
            _imgView.image = img;
        }
    }
}
///文本处理,主要是设置文本的宽高
- (void)p_actionForInitTextLabel {
    if (_text) {
        _textLbl.text = _text;
        _textLbl.font = _textFont;
        _textLbl.textColor = _textColor;
    }
    if (_attText) {
        _textLbl.attributedText = _attText;
    }
    [_textLbl sizeToFit];
    CGRect frame = _textLbl.frame;
    _textLbl.frame = CGRectMake(0, 0, _textLbl.preferredMaxLayoutWidth, frame.size.height);
}
///子文本处理,主要是设置子文本的宽高
- (void)p_actionForInitSubTextLabel {
    if (_subText) {
        _subTextLbl.text = _subText;
        _subTextLbl.font = _subTextFont;
        _subTextLbl.textColor = _subTextColor;
    }
    if (_subAttText) {
        _subTextLbl.attributedText = _subAttText;
    }
    [_subTextLbl sizeToFit];
    CGRect frame = _subTextLbl.frame;
    _subTextLbl.frame = CGRectMake(0, 0, _subTextLbl.preferredMaxLayoutWidth, frame.size.height);
}
///text view处理,主要是设置子text view的宽高
- (void)p_actionForInitTextView {
    if (_textViewAllowInput) {//允许输入
        _textView.frame = CGRectMake(0, 0, self.frame.size.width-_marginLeftXTextView-_marginRightXTextView, _textViewHeight);
    }else {//不允许输入
        _textView.text = _textViewText;
        _textView.attributedText = _textViewAttText;
        _textView.delegate = self;
        
        if (_textViewText || _textViewAttText) {
            CGSize size = [_textView sizeThatFits:CGSizeMake(self.frame.size.width-_marginLeftXTextView-_marginRightXTextView, CGFLOAT_MAX)];
            _textView.frame = CGRectMake(0, 0, self.frame.size.width-_marginLeftXTextView-_marginRightXTextView, size.height);
        }
    }
}
///按钮处理,主要是设置按钮的x和size
- (void)p_actionForInitButtons {
    if (_btnTitlesArr && _btnTitlesArr.count) {
        for (int i=0; i<_btnTitlesArr.count; i++) {
            UIButton* btn = UIButton.alloc.init;
            [btn setTitle:_btnTitlesArr[i] forState:UIControlStateNormal];
            
            if (_btnColorsArr && _btnColorsArr.count) {
                @try {
                    [btn setTitleColor:_btnColorsArr[i] forState:UIControlStateNormal];
                } @catch (NSException *exception) {
                    [btn setTitleColor:kLQHexColor(0x222222) forState:UIControlStateNormal];
                } @finally {
                    
                }
            }else {
                [btn setTitleColor:kLQHexColor(0x222222) forState:UIControlStateNormal];
            }
            
            if (_btnFontsArr && _btnFontsArr.count) {
                @try {
                    btn.titleLabel.font = _btnFontsArr[I];
                } @catch (NSException *exception) {
                    btn.titleLabel.font = [UIFont systemFontOfSize:15];
                } @finally {
                    
                }
            }else {
                btn.titleLabel.font = [UIFont systemFontOfSize:15];
            }
            
            if (_btnBorderWidthArr && _btnBorderWidthArr.count) {
                @try {
                    btn.layer.borderWidth = _btnBorderWidthArr[i].floatValue;
                } @catch (NSException *exception) {
                    btn.layer.borderWidth = 0;
                } @finally {
                    
                }
            }
            
            if (_btnBorderColorArr && _btnBorderColorArr.count) {
                @try {
                    btn.layer.borderColor = _btnBorderColorArr[i].CGColor;
                } @catch (NSException *exception) {
                } @finally {
                    
                }
            }
            
            if (_btnCornerRadiusArr && _btnCornerRadiusArr.count) {
                @try {
                    btn.layer.cornerRadius = _btnCornerRadiusArr[i].floatValue;
                } @catch (NSException *exception) {
                    btn.layer.cornerRadius = 0;
                } @finally {
                    
                }
            }
            if (_btnBackgroundColorsArr && _btnBackgroundColorsArr.count) {
                @try {
                    btn.backgroundColor = _btnBackgroundColorsArr[I];
                } @catch (NSException *exception) {
                    
                } @finally {
                    
                }
            }
            
            if (_queueType == LXAlertViewButtonQueueTypeHorizonal) {//水平排列
                CGFloat width = (self.frame.size.width-_marginLeftXLeftButton-_marginRightXRightButton-(_btnTitlesArr.count-1)*_marginBetweenButtons)/_btnTitlesArr.count;
                CGFloat x = _marginLeftXLeftButton+i*(width+_marginBetweenButtons);
                btn.frame = CGRectMake(x, 0, width, _btnHeight);
            }else {//垂直排列
                CGFloat width = self.frame.size.width-_marginLeftXLeftButton-_marginRightXRightButton;
                btn.frame = CGRectMake(_marginLeftXLeftButton, 0, width, _btnHeight);
            }
            btn.tag = I;
            [btn addTarget:self action:@selector(p_actionForClickButton:) forControlEvents:UIControlEventTouchUpInside];
            [self.buttonArrM addObject:btn];
            [self addSubview:btn];
        }
    }
}
///更新控件的位置
- (void)p_actionForUpdateOrigin {
    
    //计算所有控件的有效高度
    CGFloat buttonTotalHeight = 0;
    if (self.buttonArrM.count && _queueType == LXAlertViewButtonQueueTypeHorizonal) {
        buttonTotalHeight = _btnHeight;
    }else if (self.buttonArrM.count && _queueType == LXAlertViewButtonQueueTypeVertical) {
        buttonTotalHeight = self.buttonArrM.count*_btnHeight+(self.buttonArrM.count-1)*_marginBetweenButtons;
    }else {}
    
    CGFloat totalHeight = self.imgView.frame.size.height+self.textLbl.frame.size.height+self.subTextLbl.frame.size.height+self.textView.frame.size.height+buttonTotalHeight+_originY+_marginBetweenImageAndText+_marginBetweenTextAndSubText+_marginBetweenSubTextAndTextView+_marginBetweenTextViewAndButton+_marginButtonBottom;
    NSAssert(totalHeight<=self.parentView.frame.size.height, @"abnormal view's height is bigger than it's parent's");
    
    //计算控件的位置
    CGRect frame = self.imgView.frame;
    CGFloat x = (self.frame.size.width-self.imgWidth)*0.5;
    CGFloat y = _originY;
    self.imgView.frame = CGRectMake(x, y, frame.size.width, frame.size.height);
    
    frame = self.textLbl.frame;
    x = _marginLeftXText;
    y = CGRectGetMaxY(self.imgView.frame)+self.marginBetweenImageAndText;
    self.textLbl.frame = CGRectMake(x, y, frame.size.width, frame.size.height);
    
    frame = self.subTextLbl.frame;
    x = _marginLeftXSubText;
    y = CGRectGetMaxY(self.textLbl.frame)+self.marginBetweenTextAndSubText;
    self.subTextLbl.frame = CGRectMake(x, y, frame.size.width, frame.size.height);
    
    frame = self.textView.frame;
    y = CGRectGetMaxY(self.subTextLbl.frame)+_marginBetweenSubTextAndTextView;
    self.textView.frame = CGRectMake(_marginLeftXTextView, y, frame.size.width, frame.size.height);
    
    __weak typeof(self) weakself = self;
    if (_queueType == LXAlertViewButtonQueueTypeHorizonal) {//水平排列
        [self.buttonArrM enumerateObjectsUsingBlock:^(UIButton* _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            CGRect frame = obj.frame;
            obj.frame = CGRectMake(frame.origin.x, CGRectGetMaxY(weakself.textView.frame)+weakself.marginBetweenTextViewAndButton, frame.size.width, frame.size.height);
        }];
    }else {//垂直排列
        CGFloat startY = CGRectGetMaxY(self.textView.frame)+_marginBetweenTextViewAndButton;
        [self.buttonArrM enumerateObjectsUsingBlock:^(UIButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            CGFloat y = startY + idx*(obj.frame.size.height+weakself.marginBetweenButtons);
            obj.frame = CGRectMake(obj.frame.origin.x, y, obj.frame.size.width, obj.frame.size.height);
        }];
    }
    //校正alert view的最终frame
    y = (self.parentView.frame.size.height-totalHeight)*0.5;
    self.frame = CGRectMake(self.frame.origin.x, y+_marginCenterY, self.frame.size.width, totalHeight);
}
- (void)p_actionForClickButton:(UIButton *)sender {
    [self endEditing:YES];
    NSString* text = nil;
    if (self.alertEventBlock) {
        if (_textViewAllowInput) {
            text = _textView.text;
        }
        self.alertEventBlock(LXAlertViewEventTypeButtons, @(sender.tag), text);
    }
    if (self.autoHideWhenEvent) {
        [self remove];
    }
}
- (void)p_actionForClickMaskView {
    if (self.alertEventBlock) {
        self.alertEventBlock(LXAlertViewEventTypeMask, nil, nil);
    }
    if (self.autoHideWhenEvent) {
        [self remove];
    }
}
- (void)p_actionForCloseButton:(UIButton *)sender {
    if (self.autoHideWhenEvent) {
        [self remove];
    }
    if (self.alertEventBlock) {
        self.alertEventBlock(LXAlertViewEventTypeClose, nil, nil);
    }
}
- (void)remove {
    [self.maskBackView removeFromSuperview];
    [self removeFromSuperview];
}

#pragma mark --- UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction NS_AVAILABLE_IOS(10_0) {
    if (self.alertEventBlock) {
        self.alertEventBlock(LXAlertViewEventTypeTextView, URL.copy, nil);
    }
    return NO;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange interaction:(UITextItemInteraction)interaction NS_AVAILABLE_IOS(10_0) {
    if (self.alertEventBlock) {
        self.alertEventBlock(LXAlertViewEventTypeTextView, textAttachment, nil);
    }
    return NO;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    if (self.alertEventBlock) {
        self.alertEventBlock(LXAlertViewEventTypeTextView, URL.copy, nil);
    }
    return NO;
}
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange {
    if (self.alertEventBlock) {
        self.alertEventBlock(LXAlertViewEventTypeTextView, textAttachment, nil);
    }
    return NO;
}
- (void)dealloc {
    if (_textViewAllowInput) {
        [NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil];
        [NSNotificationCenter.defaultCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    }
    NSLog(@"dealloc --- %@", NSStringFromClass(self.class));
}

@end

实际使用工具类

LXAlertViewTool.h

//
//  LXAlertViewTool.h
//  test
//
//  Created by 天边的星星 on 2019/6/18.
//  Copyright © 2019 starxin. All rights reserved.
//

#import 
#import "LXAlertView.h"

NS_ASSUME_NONNULL_BEGIN

@interface LXAlertViewTool : NSObject

///开启相机授权
+ (void)alertViewAuthorizationCameraInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback;

///登录领取成长值
+ (LXAlertView *)alertViewLoginGetGrowthValueInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback;

///隐私政策
+ (LXAlertView *)alertViewPrivacyPolicyInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback;

///订单推送通知
+ (LXAlertView *)alertViewPushNotificationInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback;

///提示登录
+ (LXAlertView *)alertViewLoginTextInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj, NSString* text))callback;

//按钮垂直排列
+ (void)alertViewVerticalButtonsInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback;

@end

NS_ASSUME_NONNULL_END

LXAlertViewTool.m文件

//
//  LXAlertViewTool.m
//  test
//
//  Created by 刘欣 on 2019/6/18.
//  Copyright © 2019 starxin. All rights reserved.
//

#import "LXAlertViewTool.h"
#import "LXAlertView.h"

@implementation LXAlertViewTool

+ (void)alertViewAuthorizationCameraInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback {
    LXAlertView* alertView = [[LXAlertView alloc] init];
    alertView.alertViewWidth = inView.frame.size.width-100;
    
    alertView.closeImgName = @"closed_btn";
    
    alertView.imgName = @"xiangji";
    alertView.imgWidth = 100;
    alertView.imgHeight = 80;
    
    alertView.text = @"开启相机权限";
    alertView.textFont = [UIFont boldSystemFontOfSize:18];
    alertView.textColor = [UIColor colorWithRed:34.0/255.0 green:34.0/255.0 blue:34.0/255.0 alpha:1.0];
    
    alertView.subText = @"开启后才能进行拍摄或是扫二维码";
    alertView.subTextColor = [UIColor colorWithRed:119.0/255.0 green:119.0/255.0 blue:119.0/255.0 alpha:1.0];
    alertView.subTextBackgroundColor = UIColor.whiteColor;
    
    alertView.textViewHeight = 0;
    
    alertView.btnTitlesArr = @[@"去开启"];
    alertView.btnFontsArr = @[[UIFont boldSystemFontOfSize:15]];
    UIColor* color = [UIColor colorWithRed:76.0/255.0 green:147.0/255.0 blue:247.0/255.0 alpha:1.0];
    alertView.btnColorsArr = @[color.copy];
    
    color = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:0.1];
    alertView.btnBorderColorArr = @[color];
    alertView.queueType = LXAlertViewButtonQueueTypeHorizonal;
    alertView.btnBorderWidthArr = @[@1.0];
    
    alertView.marginBetweenImageAndText = 16;
    alertView.marginBetweenTextAndSubText = 10;
    alertView.marginBetweenSubTextAndTextView = 0;
    alertView.marginBetweenTextViewAndButton = 10;
    alertView.marginLeftXSubText = 20;
    alertView.marginRightXSubText = 20;
    alertView.marginLeftXLeftButton = -1;
    alertView.marginRightXRightButton = -1;
    
    alertView.marginButtonBottom = -1;
    alertView.alertEventBlock = ^(LXAlertViewEventType eventType, id  _Nullable obj, NSString * _Nullable text) {
        if (callback) {
            callback(eventType, obj);
        }
    };
    
    alertView.backgroundColor = UIColor.whiteColor;
    alertView.layer.cornerRadius = 2;
    [inView addSubview:alertView];
}
+ (LXAlertView *)alertViewLoginGetGrowthValueInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback; {
    
    LXAlertView* alertView = [[LXAlertView alloc] init];
    alertView.alertViewWidth = inView.frame.size.width-100;
    
    alertView.closeImgName = @"closed_btn";
    
    alertView.imgName = @"tree";
    
    UIColor* color = [UIColor colorWithRed:34.0/255.0 green:34.0/255.0 blue:34.0/255.0 alpha:1.0];
    UIFont* font = [UIFont systemFontOfSize:16];
    NSMutableAttributedString* attText = [[NSMutableAttributedString alloc] initWithString:@"你已获得+5成长值" attributes:@{NSForegroundColorAttributeName:color.copy, NSFontAttributeName:font}];
    color = [UIColor colorWithRed:233.0/255.0 green:83.0/255 blue:95.0/255.0 alpha:1.0];
    [attText addAttributes:@{NSForegroundColorAttributeName:color, NSFontAttributeName:font} range:NSMakeRange(4, 2)];
    alertView.attText = attText.copy;
    
    alertView.textViewHeight = 0;
    alertView.btnTitlesArr = @[@"登录领取"];
    alertView.btnColorsArr = @[UIColor.whiteColor];
    alertView.btnFontsArr  = @[[UIFont systemFontOfSize:20]];
    alertView.btnBackgroundColorsArr = @[color];
    alertView.btnCornerRadiusArr = @[@4];
    
    alertView.marginLeftXText = 0;
    alertView.marginRightXText = 0;
    alertView.marginBetweenImageAndText = 16;
    alertView.marginBetweenTextAndSubText = 0;
    alertView.marginBetweenSubTextAndTextView = 0;
    alertView.marginBetweenTextViewAndButton = 20;
    alertView.marginLeftXLeftButton = 20;
    alertView.marginRightXRightButton = 20;
    alertView.textViewHeight = 0;
    
    alertView.autoHideWhenEvent = NO;
    alertView.alertEventBlock = ^(LXAlertViewEventType eventType, id  _Nullable obj, NSString * _Nullable text) {
        if (callback) {
            callback(eventType, obj);
        }
    };
    
    [inView addSubview:alertView];
    
    alertView.transform = CGAffineTransformMakeScale(0, 0);
    alertView.maskBackView.alpha = 0.0;
    
    return alertView;
}
+ (LXAlertView *)alertViewPrivacyPolicyInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback; {
    LXAlertView* alertView = [[LXAlertView alloc] init];
    alertView.alertViewWidth = inView.frame.size.width-100;
    
    alertView.text = @"程序员开发隐私政策";
    alertView.textColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0];
    alertView.textFont = [UIFont boldSystemFontOfSize:16];
    
    NSMutableAttributedString* attText = [[NSMutableAttributedString alloc] init];
    
    NSMutableParagraphStyle* style = [[NSMutableParagraphStyle alloc] init];
    style.lineSpacing = 1;
    style.paragraphSpacing = 5;
    
    NSString* text = @"感谢您使用程序员宣言!为帮助您安全使用产品和服务,在您同意并授权的基础上,我们可能会收集您公司的名称、法定联系人、加班情况、位置信息等,以便政府及时遏制996加班制度。请您在使用前务必仔细阅读并透彻理解";
    UIColor* color = [UIColor colorWithRed:145.0/255.0 green:145.0/255.0 blue:145.0/255.0 alpha:1.0];
    UIFont* font = [UIFont systemFontOfSize:14];
    
    NSAttributedString* att1 = [[NSAttributedString alloc] initWithString:text.copy attributes:@{NSForegroundColorAttributeName:color.copy, NSFontAttributeName:font.copy, NSParagraphStyleAttributeName:style}];
    [attText appendAttributedString:att1.copy];
    
    NSURL* url = [NSURL URLWithString:@"https://996.icu/#/zh_CN"];
    color = [UIColor colorWithRed:138.0/255.0 green:194.0/255.0 blue:239.0/255.0 alpha:1.0];
    att1 = [[NSAttributedString alloc] initWithString:@"《996程序员抗争宣言》" attributes:@{NSLinkAttributeName:url,NSForegroundColorAttributeName:color.copy, NSFontAttributeName:font.copy,NSParagraphStyleAttributeName:style}];
    [attText appendAttributedString:att1.copy];
    
    text = @"\n如您同意此政策,请点击\"同意\"并开始使用我们的产品和服务,我们尽全力保护您的个人信息安全";
    font = [UIFont systemFontOfSize:13];
    color = [UIColor colorWithRed:209.0/255.0 green:209.0/255.0 blue:209.0/255.0 alpha:1.0];
    att1 = [[NSAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName:color.copy, NSFontAttributeName:font.copy,NSParagraphStyleAttributeName:style}];
    
    [attText appendAttributedString:att1.copy];
    
    NSTextAttachment* attachment = [[NSTextAttachment alloc] init];
    attachment.image = [UIImage imageNamed:@"circle"];
    att1 = [NSAttributedString attributedStringWithAttachment:attachment];
    attachment.bounds = CGRectMake(0, -4, 15, 15);
    [attText appendAttributedString:att1.copy];
    
    alertView.textViewAttText = attText.copy;
    alertView.textViewAllowInput = NO;
    
    color = [UIColor colorWithRed:164.0/255.0 green:164.0/255.0 blue:164.0/255.0 alpha:1.0];
    font = [UIFont systemFontOfSize:14];
    alertView.btnTitlesArr = @[@"不同意", @"同意"];
    alertView.btnColorsArr = @[color.copy,UIColor.whiteColor];
    alertView.btnBackgroundColorsArr = @[UIColor.whiteColor, [UIColor colorWithRed:75.0/255.0 green:149.0/255.0 blue:247.0/255.0 alpha:1.0]];
    alertView.btnFontsArr = @[font.copy,font.copy];
    alertView.btnBorderColorArr = @[UIColor.lightGrayColor,UIColor.clearColor];
    alertView.btnBorderWidthArr = @[@(1.0/UIScreen.mainScreen.scale),@0];
    alertView.btnCornerRadiusArr = @[@2,@2];
    alertView.btnHeight = 32;
    
    alertView.marginLeftXTextView = 8;
    alertView.marginRightXTextView = 8;
    alertView.marginLeftXLeftButton = 16;
    alertView.marginRightXRightButton = 16;
    alertView.marginBetweenButtons = 10;
    alertView.marginButtonBottom = 10;
    alertView.marginBetweenImageAndText = 0;
    alertView.marginBetweenTextAndSubText = 0;
    alertView.marginBetweenSubTextAndTextView = 0;
    alertView.marginBetweenTextViewAndButton = 0;
    
    alertView.autoHideWhenEvent = NO;
    alertView.alertEventBlock = ^(LXAlertViewEventType eventType, id  _Nullable obj, NSString * _Nullable text) {
        if (callback) {
            callback(eventType, obj);
        }
    };;
    
    alertView.layer.cornerRadius = 4;
    [inView addSubview:alertView];
    alertView.transform = CGAffineTransformMakeScale(0, 0);
    alertView.maskBackView.alpha = 0.0;
    
    return alertView;
}
+ (LXAlertView *)alertViewPushNotificationInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback {
    LXAlertView* alertView = [[LXAlertView alloc] init];
    alertView.alertViewWidth = inView.frame.size.width-100;
    
    alertView.imgName = @"push";
    alertView.imgWidth = 140;
    alertView.imgHeight = 100;
    
    alertView.text = @"打开推送通知";
    alertView.textColor = UIColor.blackColor;
    alertView.textFont = [UIFont boldSystemFontOfSize:18];
    alertView.textAlignment = NSTextAlignmentLeft;
    
    alertView.subText = @"允许推送通知,才不会错过成功报名的消息哦";
    alertView.subTextFont = [UIFont systemFontOfSize:13];
    alertView.subTextColor = [UIColor colorWithRed:199.0/255.0 green:199.0/255.0 blue:199.0/255.0 alpha:1.0];
    alertView.subTextAlignment = NSTextAlignmentLeft;
    
    alertView.textViewHeight = 0;
    
    alertView.btnTitlesArr = @[@"下次再说",@"打开通知"];
    UIColor* color1 = [UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0];
    UIColor* color2 = [UIColor colorWithRed:75.0/255.0 green:149.0/255.0 blue:247.0/255.0 alpha:1.0];
    alertView.btnColorsArr = @[color1.copy,color2.copy];
    alertView.btnBorderWidthArr = @[@(1.0/UIScreen.mainScreen.scale),@(1.0/UIScreen.mainScreen.scale)];
    
    color1 = [UIColor.lightGrayColor colorWithAlphaComponent:0.3];
    alertView.btnBorderColorArr = @[color1.copy,color1.copy];
    UIFont* font = [UIFont systemFontOfSize:13];
    alertView.btnFontsArr = @[font,font];
    alertView.btnHeight = 34;
    
    alertView.marginBetweenImageAndText = 20;
    alertView.marginBetweenTextAndSubText = 8;
    alertView.marginBetweenSubTextAndTextView = 0;
    alertView.marginBetweenTextViewAndButton = 15;
    alertView.marginButtonBottom = -1;
    alertView.marginLeftXText = 10;
    alertView.marginRightXText = 10;
    alertView.marginLeftXSubText = 10;
    alertView.marginRightXSubText = 10;
    alertView.marginLeftXLeftButton = 0;
    alertView.marginRightXRightButton = 0;
    alertView.marginBetweenButtons = 0;
    
    alertView.layer.cornerRadius = 4;
    alertView.autoHideWhenEvent = NO;
    alertView.alertEventBlock = ^(LXAlertViewEventType eventType, id  _Nullable obj, NSString * _Nullable text) {
        if (callback) {
            callback(eventType, obj);
        }
    };;
    
    [inView addSubview:alertView];
    alertView.maskBackView.alpha = 0.0;
    alertView.transform = CGAffineTransformMakeScale(0, 0);
    
    return alertView;
}
+ (LXAlertView *)alertViewLoginTextInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj, NSString* text))callback {
    LXAlertView* alertView = [[LXAlertView alloc] init];
    alertView.alertViewWidth = inView.frame.size.width-100;
    
    alertView.text = @"提示";
    alertView.textFont = [UIFont boldSystemFontOfSize:20];
    alertView.textColor = UIColor.blackColor;
    
    alertView.subText = @"确定退出登录?";
    alertView.subTextFont = [UIFont systemFontOfSize:16];
    alertView.subTextColor = UIColor.blackColor;
    
    alertView.textViewHeight = 30;
    alertView.textViewAllowInput = YES;
    alertView.textViewTextFont = [UIFont systemFontOfSize:16];
    alertView.textViewTextColor = UIColor.darkGrayColor;
    alertView.textViewBorderColor = [UIColor colorWithRed:170.0/255.0 green:170.0/255.0 blue:170.0/255.0 alpha:1.0];
    alertView.textViewBorderWidth = 1.0;
    
    alertView.btnTitlesArr = @[@"取消",@"确定"];
    UIColor* color1 = [UIColor colorWithRed:79.0/255.0 green:136.0/255.0 blue:240.0/255.0 alpha:1.0];
    UIColor* color2 = [UIColor colorWithRed:92.0/255.0 green:154.0/255.0 blue:242.0/255.0 alpha:1.0];
    alertView.btnFontsArr = @[[UIFont systemFontOfSize:20],[UIFont systemFontOfSize:20]];
    alertView.btnColorsArr = @[color1.copy,color2.copy];
    color1 = [UIColor.lightGrayColor colorWithAlphaComponent:0.3];
    alertView.btnBorderColorArr = @[color1.copy,color1.copy];
    alertView.btnBorderWidthArr = @[@(0.5),@0.5];
    
    alertView.marginBetweenImageAndText = 0;
    alertView.marginBetweenTextAndSubText = 8;
    alertView.marginBetweenSubTextAndTextView = 25;
    alertView.marginBetweenTextViewAndButton = 15;
    alertView.marginButtonBottom = -1;
    alertView.marginLeftXTextView = 15;
    alertView.marginRightXTextView = 15;
    alertView.marginLeftXLeftButton = 0;
    alertView.marginRightXRightButton = 0;
    alertView.marginBetweenButtons = -0.5;
    alertView.btnHeight = 40;
    
    alertView.autoHideWhenEvent = NO;
    alertView.alertEventBlock = callback;
    
    alertView.layer.cornerRadius = 4.0;
    [inView addSubview:alertView];
    alertView.transform = CGAffineTransformMakeScale(0, 0);
    alertView.maskBackView.alpha = 0.0;
    
    return alertView;
}
+ (void)alertViewVerticalButtonsInView:(UIView *)inView callback:(void (^)(LXAlertViewEventType eventType, id obj))callback {
    LXAlertView* alertView = [[LXAlertView alloc] init];
    alertView.alertViewWidth = inView.frame.size.width-100;
    
    alertView.text = @"测试垂直排列按钮";
    alertView.subText = @"垂直按钮排版,此处省去......";
    alertView.textViewHeight = 0;
    
    alertView.btnTitlesArr = @[@"按钮1",@"按钮2",@"按钮3"];
    UIFont* font = [UIFont systemFontOfSize:18];
    alertView.btnFontsArr = @[font,font,font];
    alertView.queueType = LXAlertViewButtonQueueTypeVertical;
    UIColor* color = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0];
    alertView.btnBorderColorArr = @[color,color,color];
    alertView.btnBorderWidthArr = @[@0.5,@0.5,@0.5];
    
    alertView.marginBetweenImageAndText = 0;
    alertView.marginBetweenSubTextAndTextView = 0;
    alertView.marginButtonBottom = -0.5;
    alertView.marginBetweenButtons = -0.5;
    alertView.marginLeftXLeftButton = 0;
    alertView.marginRightXRightButton = 0;
    alertView.btnHeight = 34;
    alertView.layer.cornerRadius = 4;
    alertView.layer.masksToBounds = YES;
    
    [inView addSubview:alertView];
    alertView.alertEventBlock = ^(LXAlertViewEventType eventType, id  _Nullable obj, NSString * _Nullable text) {
        if (callback) {
            callback(eventType, obj);
        }
    };
}

@end

LXAlertViewTool实际效果图

调用相机代码

 [LXAlertViewTool alertViewAuthorizationCameraInView:self.view callback:^(LXAlertViewEventType eventType, id obj){
        NSLog(@"点击了去开启---%d", eventType);
    }];
  • 效果图


    image.png

登录领取成长值代码

    __block LXAlertView* alertView = [LXAlertViewTool alertViewLoginGetGrowthValueInView:self.view callback:^(LXAlertViewEventType eventType, id obj) {
        if (eventType == LXAlertViewEventTypeClose) {
            [alertView remove];
        }else {
            [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                alertView.maskBackView.alpha = 0;
                alertView.transform = CGAffineTransformMakeScale(0.1, 0.1);
            } completion:^(BOOL finished) {
                [alertView remove];
            }];
        }
    }];
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        alertView.transform = CGAffineTransformMakeScale(1.0, 1.0);
        alertView.maskBackView.alpha = 1.0;
    } completion:nil];
  • 效果图


    image.png

隐私政策代码

   __block LXAlertView* alertView = [LXAlertViewTool alertViewPrivacyPolicyInView:self.view callback:^(LXAlertViewEventType eventType, id  _Nonnull obj) {
        if (eventType == LXAlertViewEventTypeTextView) {
            NSLog(@"attachment=%@", obj);
        }else {
            NSLog(@"idx=%@", obj);
        }
    }];
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        alertView.transform = CGAffineTransformMakeScale(1.0, 1.0);
        alertView.maskBackView.alpha = 1.0;
    } completion:nil];
  • 效果图


    image.png

订单推送通知代码

    __block LXAlertView* alertView = [LXAlertViewTool alertViewPushNotificationInView:self.view callback:^(LXAlertViewEventType eventType, id  _Nonnull obj) {
        NSLog(@"idx=%@", obj);
        [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            alertView.transform = CGAffineTransformMakeScale(0.1, 0.1);
            alertView.maskBackView.alpha = 0.0;
        } completion:^(BOOL finished) {
            [alertView remove];
        }];
    }];
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        alertView.transform = CGAffineTransformMakeScale(1.0, 1.0);
        alertView.maskBackView.alpha = 1.0;
    } completion:nil];
  • 效果图


    image.png

提示登录代码

   __block LXAlertView* alertView = [LXAlertViewTool alertViewLoginTextInView:self.view callback:^(LXAlertViewEventType eventType, id  _Nonnull obj, NSString* text) {
        NSLog(@"idx=%@,text=%@", obj,text);
        [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            alertView.transform = CGAffineTransformMakeScale(0.1, 0.1);
            alertView.maskBackView.alpha = 0.0;
        } completion:^(BOOL finished) {
            [alertView remove];
        }];
    }];
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        alertView.transform = CGAffineTransformMakeScale(1.0, 1.0);
        alertView.maskBackView.alpha = 1.0;
    } completion:nil];
  • 效果图


    image.png

垂直排列按钮代码

[LXAlertViewTool alertViewVerticalButtonsInView:self.view callback:^(LXAlertViewEventType eventType, id  _Nonnull obj) {
        NSLog(@"obj=%@", obj);
    }];
  • 效果图


    image.png

你可能感兴趣的:(弹窗控件:LXAlertView,可定制化大多数弹窗)