123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- //
- // LiveRoomAlertView.m
- // TeacherDaya
- //
- // Created by 王智 on 2022/6/16.
- // Copyright © 2022 DayaMusic. All rights reserved.
- //
- #import "LiveRoomAlertView.h"
- #import "UIView+Animation.h"
- typedef enum : NSUInteger {
- LiveRoomAlertViewCancel,
- LiveRoomAlertViewConfirm,
- } LiveRoomAlertViewActionTag;
- #define ContainerWidth 320
- #define ContainerHeight 180
- @interface LiveRoomAlertView ()
- @property (nonatomic, strong) UILabel *tipsLabel;
- @property (nonatomic, strong) UILabel *titleLable;
- @property (nonatomic, strong) UIButton *cancelButton;
- @property (nonatomic, strong) UIButton *sureButton;
- @property (nonatomic, strong) NSString *title;
- @property (nonatomic, strong) NSString *leftTitle;
- @property (nonatomic, strong) NSString *rightTitle;
- @property (nonatomic, copy) LiveAlertCallback cancel;
- @property (nonatomic, copy) LiveAlertCallback confirm;
- @end
- @implementation LiveRoomAlertView
- + (LiveRoomAlertView *)liveroomAlertWithTitle:(NSString *)title leftButtonTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle inView:(UIView *)displayView cancel:(LiveAlertCallback)cancel confirm:(LiveAlertCallback)confirm {
- LiveRoomAlertView *alertView = [[LiveRoomAlertView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, KPortraitHeight)];
- alertView.backgroundColor = HexRGBAlpha(0x000000, 0.5f);
- alertView.title = title;
- alertView.leftTitle = leftTitle;
- alertView.rightTitle = rightTitle;
- alertView.cancel = cancel;
- alertView.confirm = confirm;
- [alertView addSubviews];
- [alertView showAlertInView:displayView];
- return alertView;
- }
- - (void)addSubviews {
- UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake((kScreenWidth - ContainerWidth) / 2, (CGRectGetHeight(self.bounds) - ContainerHeight) / 2, ContainerWidth, ContainerHeight)];
- contentView.backgroundColor = [UIColor whiteColor];
- contentView.layer.cornerRadius = 8.0f;
- contentView.layer.masksToBounds = YES;
- [self addSubview:contentView];
-
- [contentView addSubview:self.titleLable];
- [contentView addSubview:self.cancelButton];
- [contentView addSubview:self.sureButton];
-
- CGFloat width = (ContainerWidth - 1) / 2.0f;
-
- [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(contentView.mas_left);
- make.bottom.equalTo(contentView.mas_bottom);
- make.height.mas_equalTo(47);
- make.width.mas_equalTo(width);
- }];
-
- [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.cancelButton.mas_right);
- make.bottom.mas_equalTo(contentView.mas_bottom);
- make.height.mas_equalTo(47);
- make.width.mas_equalTo(width);
- }];
-
- UIView *buttonSpaceLineView = [[UIView alloc] initWithFrame:CGRectZero];
- buttonSpaceLineView.backgroundColor = HexRGB(0xDEDEDE);
- [contentView addSubview:buttonSpaceLineView];
-
- [buttonSpaceLineView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.cancelButton.mas_right);
- make.top.bottom.mas_equalTo(self.cancelButton);
- make.width.mas_equalTo(1);
- }];
-
- UIView *headLine = [[UIView alloc] initWithFrame:CGRectZero];
- headLine.backgroundColor = HexRGB(0xDEDEDE);
- [contentView addSubview:headLine];
- [headLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(contentView);
- make.height.mas_equalTo(1);
- make.bottom.mas_equalTo(self.cancelButton.mas_top);
- }];
-
- [self.titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(contentView.mas_top).offset(30);
- make.left.equalTo(contentView.mas_left).offset(36);
- make.right.equalTo(contentView.mas_right).offset(-36);
- make.bottom.mas_greaterThanOrEqualTo(self.sureButton.mas_top).offset(-15);
- }];
-
- }
- - (void)showAlertInView:(UIView *)displayView {
- _isShow = YES;
- [displayView addSubview:self];
- [displayView bringSubviewToFront:self];
- [self setPopAnimation];
- }
- - (void)dismissAlertView {
- _isShow = NO;
- [self removeFromSuperview];
- }
- - (void)buttonAction:(UIButton *)button {
- if (button.tag == LiveRoomAlertViewCancel) {
- if (self.cancel) {
- self.cancel();
- }
- }else {
- if (self.confirm) {
- self.confirm();
- }
- }
- [self dismissAlertView];
- }
- - (UILabel *)titleLable {
- if (!_titleLable) {
- _titleLable = [[UILabel alloc] init];
- _titleLable.font = [UIFont systemFontOfSize:14.0f];
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//调整行间距
- [paragraphStyle setAlignment:NSTextAlignmentCenter];
- NSMutableAttributedString *attrs = [[NSMutableAttributedString alloc] initWithString:self.title attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f],NSForegroundColorAttributeName:HexRGB(0x666666)}];
- _titleLable.attributedText = attrs;
- _titleLable.numberOfLines = 0;
- _titleLable.lineBreakMode = NSLineBreakByTruncatingMiddle;
- }
- return _titleLable;
- }
- - (UIButton *)cancelButton {
- if(!_cancelButton) {
- _cancelButton = [[UIButton alloc] init];
- _cancelButton.backgroundColor = [UIColor clearColor];
- [_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:16.0f]];
- [_cancelButton setTitleColor:HexRGB(0x666666) forState:UIControlStateNormal];
- [_cancelButton setTitle:self.leftTitle forState:UIControlStateNormal];
- _cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- _cancelButton.tag = LiveRoomAlertViewCancel;
- [_cancelButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
-
- }
- return _cancelButton;
- }
- - (UIButton *)sureButton {
- if (!_sureButton) {
- _sureButton = [[UIButton alloc] init];
- _sureButton.backgroundColor = [UIColor clearColor];
- [_sureButton.titleLabel setFont:[UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium]];
- [_sureButton setTitleColor:HexRGB(0x333333) forState:UIControlStateNormal];
- [_sureButton setTitle:self.rightTitle forState:UIControlStateNormal];
- _sureButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
- _sureButton.tag = LiveRoomAlertViewConfirm;
- [_sureButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _sureButton;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|