123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- //
- // RQAlertViewManager.m
- // SDJK
- //
- // Created by 张嵘 on 2021/8/17.
- //
- #import "RQAlertViewManager.h"
- @interface RQAlertViewManager ()
- @property (nonatomic, readwrite, strong) SCLAlertView *alert;
- @property (nonatomic, readwrite, strong) UITextView *messageTextView;
- @property (nonatomic, readwrite, strong) SCLButton *rePlayButton;
- @property (nonatomic, readwrite, strong) SCLButton *closeButton;
- @property (nonatomic, readwrite, assign) BOOL isShow;
- @end
- @implementation RQAlertViewManager
- @def_singleton(RQAlertViewManager);
- - (void)rq_showOfficialInterpretationAlertWithMessage:(NSString *)messageStr mp3Url:(NSString *)mp3Url {
-
- SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
- @weakify(alert)
- CGFloat viewTextWideth = RQ_SCREEN_WIDTH - (20 * 2) - (40 * 2);
- CGFloat textHeight = [messageStr heightForFont:[UIFont systemFontOfSize:13] width:viewTextWideth] > RQ_SCREEN_HEIGHT / 2.f? RQ_SCREEN_HEIGHT / 2.f : [messageStr heightForFont:[UIFont systemFontOfSize:13] width:viewTextWideth];
- RQTrack *track = [[RQTrack alloc] init];
- track.audioFileURL = [NSURL URLWithString:mp3Url];
- RQ_MUSIC_MANAGER.audioTrack = track;
- [alert removeTopCircle];
- alert.tintTopCircle = NO;
- alert.useLargerIcon = NO;
- alert.iconTintColor = RQ_MAIN_COLOR;
- alert.cornerRadius = 10;
-
- alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
- alert.labelTitle.font = [UIFont boldSystemFontOfSize:15];
-
- [alert.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(20);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(viewTextWideth, 21.f));
- }];
-
- UITextView *messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, alert.labelTitle.rq_y + alert.labelTitle.rq_height, viewTextWideth, textHeight)];
- messageTextView.font = [UIFont systemFontOfSize:13];
- messageTextView.editable = NO;
- messageTextView.textColor = RQ_MAIN_TEXT_COLOR_3;
- messageTextView.textAlignment = NSTextAlignmentLeft;
- messageTextView.text = messageStr;
- [alert addCustomView:messageTextView];
-
- [messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(alert.labelTitle.mas_bottom).mas_offset(20);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(viewTextWideth, textHeight)).priority(500);
- }];
- SCLButton *closeButton = [alert addButton:@"关闭" actionBlock:^{
- @strongify(alert);
- [alert hideView];
- [RQ_MUSIC_MANAGER rq_cancelStreamer];
- }];
- closeButton.buttonFormatBlock = ^NSDictionary* (void) {
- NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
- buttonConfig[@"cornerRadius"] = @"15.f";
- buttonConfig[@"backgroundColor"] = RQ_MAIN_BACKGROUNDCOLOR;
- buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_3;
- buttonConfig[@"borderWidth"] = @1.0f;
- buttonConfig[@"borderColor"] = RQ_MAIN_TEXT_COLOR_3;
- buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
- return buttonConfig;
- };
-
- [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(messageTextView.mas_bottom).mas_offset(20);
- make.left.mas_equalTo(messageTextView.mas_left);
- make.bottom.mas_offset(-20);
- make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 30.f));
- }];
-
- SCLButton *rePlayButton = [alert addButton:@"语音重播" validationBlock:^BOOL{
- [RQ_MUSIC_MANAGER rq_resetStreamer];
- return NO;
- } actionBlock:nil];
- rePlayButton.buttonFormatBlock = ^NSDictionary* (void) {
- NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
- buttonConfig[@"cornerRadius"] = @"15.f";
- buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
- buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
- buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
- return buttonConfig;
- };
-
- [rePlayButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(messageTextView.mas_right);
- make.bottom.mas_offset(-20);
- make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 30.f));
- }];
-
- alert.horizontalButtons = YES;
- alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
- [alert showTitle:@"官方解释" subTitle:nil style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
- [RQ_MUSIC_MANAGER rq_resetStreamer];
- }
- - (void)rq_showSkillExplanationAlertWithMessage:(NSString *)messageStr skillkeyword:(NSString *)skillkeyword explainGifUrl:(NSString *)explainGifUrl mp3Url:(NSString *)mp3Url completeBlock:(void(^__nullable)(void))completeBlock {
- if (_isShow) {
- return;
- }
- self.messageTextView = nil;
- self.alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
- [_alert removeTopCircle];
- _alert.tintTopCircle = NO;
- _alert.useLargerIcon = NO;
- _alert.iconTintColor = RQ_MAIN_COLOR;
- _alert.cornerRadius = 10;
- _alert.horizontalButtons = YES;
- _alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
- _alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
- _alert.labelTitle.font = [UIFont boldSystemFontOfSize:15];
- CGFloat viewTextWideth = RQ_SCREEN_WIDTH - (20 * 2) - (40 * 2);
- CGFloat textHeight = [messageStr heightForFont:[UIFont systemFontOfSize:13] width:viewTextWideth] > RQ_SCREEN_HEIGHT / 2.f? RQ_SCREEN_HEIGHT / 2.f : [messageStr heightForFont:[UIFont systemFontOfSize:13] width:viewTextWideth];
-
- RQTrack *track = [[RQTrack alloc] init];
- track.audioFileURL = [NSURL URLWithString:mp3Url];
- RQ_MUSIC_MANAGER.audioTrack = track;
-
- [self.alert.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(20);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(viewTextWideth, 21.f));
- }];
- UIImageView *gifImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_alert.labelTitle.rq_x, _alert.labelTitle.rq_y + _alert.labelTitle.rq_height, viewTextWideth, viewTextWideth * 0.5)];
- [gifImageView sd_setImageWithURL:[NSURL URLWithString:explainGifUrl] placeholderImage:RQWebImagePlaceholder()];
-
- if (RQStringIsNotEmpty(explainGifUrl)) {
- [_alert addCustomView:gifImageView];
- [gifImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(_alert.labelTitle.mas_bottom).mas_offset(20);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(viewTextWideth, viewTextWideth * 0.5));
- }];
- }
-
- if (RQStringIsNotEmpty(messageStr)) {
- UILabel *textViewTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_alert.labelTitle.rq_x, RQStringIsNotEmpty(explainGifUrl)? gifImageView.rq_y + gifImageView.rq_height : _alert.labelTitle.rq_y + _alert.labelTitle.rq_height, 88, 18)];
- textViewTitleLabel.text = @"本题速记口诀";
- textViewTitleLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
- textViewTitleLabel.font = [UIFont systemFontOfSize:13];
- textViewTitleLabel.textAlignment = NSTextAlignmentCenter;
- [_alert addCustomView:textViewTitleLabel];
- [textViewTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(RQStringIsNotEmpty(explainGifUrl)? gifImageView.mas_bottom : _alert.labelTitle.mas_bottom).mas_offset(20);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(88, 18));
- }];
-
- UIImageView *leftLineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 1)];
- leftLineImageView.backgroundColor = RQ_MAIN_TEXT_COLOR_5;
- [_alert addCustomView:leftLineImageView];
- [leftLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(textViewTitleLabel);
- make.right.mas_equalTo(textViewTitleLabel.mas_left).mas_offset(- 5);
- make.size.mas_equalTo(CGSizeMake(20, 1));
- }];
- UIImageView *rightLineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 1)];
- rightLineImageView.backgroundColor = RQ_MAIN_TEXT_COLOR_5;
- [_alert addCustomView:rightLineImageView];
- [rightLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(textViewTitleLabel);
- make.left.mas_equalTo(textViewTitleLabel.mas_right).mas_offset(5);
- make.size.mas_equalTo(CGSizeMake(20, 1));
- }];
- self.messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(_alert.labelTitle.rq_x, textViewTitleLabel.rq_y + textViewTitleLabel.rq_height, viewTextWideth, textHeight)];
- self.messageTextView.font = [UIFont systemFontOfSize:13];
- self.messageTextView.editable = NO;
- self.messageTextView.textColor = RQ_MAIN_TEXT_COLOR_3;
- self.messageTextView.textAlignment = NSTextAlignmentLeft;
- [_alert addCustomView:self.messageTextView];
-
- if (RQStringIsNotEmpty(skillkeyword)) {
- NSMutableAttributedString *abs = [[NSMutableAttributedString alloc] initWithString:messageStr? : @""];
- [[[skillkeyword componentsSeparatedByString:@"-"].rac_sequence.signal deliverOnMainThread] subscribeNext:^(NSString * _Nullable skillkeywordStr) {
- NSRange targetRange = NSMakeRange(0, messageStr.length);
- NSRange range = targetRange;
- while (true) {
- range = [messageStr rangeOfString:skillkeywordStr options:NSLiteralSearch range:targetRange];
-
- if (range.location != NSNotFound) {
- NSRange newRange = NSMakeRange(range.location - 1, range.length + 2);
- NSString *keywordStr = [messageStr substringWithRange:newRange];
- if ([keywordStr containsString:@"“"] || [keywordStr containsString:@"”"] || [keywordStr containsString:@"\""]) {
- range = newRange;
- }
- targetRange = NSMakeRange(NSMaxRange(range), messageStr.length-NSMaxRange(range));
-
- [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:range];
- [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:targetRange];
- [abs addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:range];
- } else {
- break;
- }
- }
-
-
- } completed:^{
- self.messageTextView.attributedText = abs;
- }];
- } else {
- self.messageTextView.text = messageStr;
- }
-
-
- [self.messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(textViewTitleLabel.mas_bottom).mas_offset(15);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(viewTextWideth, textHeight)).priority(500);
- }];
- }
-
- @weakify(self)
- self.closeButton = [self.alert addButton:@"关闭" actionBlock:^{
- @strongify(self);
- if (RQ_COMMON_MANAGER.isAutoRead) {
- completeBlock();
- }
- [self.alert hideView];
- _isShow = NO;
- [RQ_COMMON_MANAGER cancleAutoReadQuestion];
- }];
- self.closeButton.buttonFormatBlock = ^NSDictionary* (void) {
- NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
- buttonConfig[@"cornerRadius"] = @"15.f";
- buttonConfig[@"backgroundColor"] = RQ_MAIN_BACKGROUNDCOLOR;
- buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_3;
- buttonConfig[@"borderWidth"] = @1.0f;
- buttonConfig[@"borderColor"] = RQ_MAIN_TEXT_COLOR_3;
- buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
- return buttonConfig;
- };
-
- [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- if (self.messageTextView) {
- make.top.mas_equalTo(self.messageTextView.mas_bottom).mas_offset(20);
- } else {
- make.top.mas_equalTo(RQStringIsNotEmpty(explainGifUrl)? gifImageView.mas_bottom : _alert.labelTitle.mas_bottom).mas_offset(20);
- }
- make.left.mas_equalTo(_alert.labelTitle.mas_left);
- make.bottom.mas_offset(-20);
- make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 30.f));
- }];
-
- self.rePlayButton = [self.alert addButton:@"语音重播" validationBlock:^BOOL{
- [RQ_MUSIC_MANAGER rq_resetStreamer];
- return NO;
- } actionBlock:nil];
- self.rePlayButton.buttonFormatBlock = ^NSDictionary* (void) {
- NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
- buttonConfig[@"cornerRadius"] = @"15.f";
- buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
- buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
- buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
- return buttonConfig;
- };
-
- [self.rePlayButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(_alert.labelTitle.mas_right);
- make.bottom.mas_offset(-20);
- make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 30.f));
- }];
-
- [_alert showTitle:@"技巧讲解" subTitle:nil style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
- _isShow = YES;
- if (RQ_COMMON_MANAGER.isAutoRead) {
- [RQ_MUSIC_MANAGER rq_resetStreamerWithDOUAudioStreamerStatusBlock:^(DOUAudioStreamerStatus status) {
- if (status == DOUAudioStreamerFinished) {
- completeBlock();
- [_alert hideView];
- _isShow = NO;
- }
- }];
- } else {
- [RQ_MUSIC_MANAGER rq_resetStreamer];
- }
- }
- - (void)rq_ActivateVIPAlertWithComplete:(VoidBlock_Bool)complete {
-
- SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
- @weakify(alert)
- [alert removeTopCircle];
- alert.tintTopCircle = NO;
- alert.useLargerIcon = NO;
- alert.shouldDismissOnTapOutside = YES;
- alert.iconTintColor = RQ_MAIN_COLOR;
- alert.cornerRadius = 10;
-
- alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
- alert.labelTitle.font = [UIFont boldSystemFontOfSize:15];
-
- UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 250, 30)];
- textFiled.borderStyle = UITextBorderStyleNone;
- textFiled.backgroundColor = RQ_LIST_BACKGROUNDCOLOR;
- textFiled.layer.cornerRadius = 15;
- textFiled.layer.borderWidth = 1;
- textFiled.layer.borderColor = RQ_MAIN_LINE_COLOR_1.CGColor;
- textFiled.clipsToBounds = YES;
- UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
- UIImageView *imageView = [[UIImageView alloc]initWithImage:RQImageNamed(@"activationIcon")];
- imageView.center = leftView.center;
- [leftView addSubview:imageView];
- textFiled.leftView = imageView;
- textFiled.leftViewMode = UITextFieldViewModeAlways; //此处用来设置leftview现实时机
- textFiled.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
- textFiled.placeholder = @"请输入激活码";
- textFiled.tintColor = [UIColor colorWithHexString:@"#BFBFBF"];
- textFiled.textColor = RQ_MAIN_TEXT_COLOR_3;
- textFiled.font = [UIFont systemFontOfSize:13];
- [alert addCustomTextField:textFiled];
-
- SCLButton *closeButton = [alert addButton:@"" actionBlock:^{
- @strongify(alert);
- [alert hideView];
- if (complete) {
- complete(NO);
- }
- }];
- [closeButton setImage:RQImageNamed(@"close") forState:UIControlStateNormal];
- [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(14);
- make.right.mas_offset(-14);
- make.size.mas_equalTo(CGSizeMake(16.f, 16.f));
- }];
-
- SCLButton *activateBtn = [alert addButton:@"立即开通" validationBlock:^BOOL{
- if (textFiled.text.length <= 0) {
- [MBProgressHUD rq_showTips:@"请输入激活码"];
- }
- return textFiled.text.length > 0;
- } actionBlock:^{
- if (complete) {
- complete(YES);
- }
- }];
- activateBtn.buttonFormatBlock = ^NSDictionary* (void) {
- NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
- buttonConfig[@"cornerRadius"] = @"15.f";
- buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
- buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
- buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
- return buttonConfig;
- };
- [activateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_offset(0);
- make.bottom.mas_offset(-20);
- make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(100.f), 30.f));
- }];
-
- alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
- [alert showTitle:@"提示" subTitle:@"您还未开通系统,请输入激活码开通!" style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
- }
- /**
- 弹出alertController,并且有两个个action按钮,分别有处理事件
-
- @param alertType 弹窗类型
- @param title title
- @param message Message
- @param confirmTitle 左边按钮的title
- @param cancelTitle 右边按钮的title
- @param confirmAction 左边按钮的点击事件
- @param cancelAction 右按钮的点击事件
- */
- - (void)showAlertWithAlertType:(RQAlertType)alertType title:(NSString * _Nullable )title message:(NSString * _Nullable )message confirmTitle:(NSString *)confirmTitle cancelTitle:(NSString * _Nullable )cancelTitle confirmAction:(void (^__nullable)(__kindof QMUIDialogViewController *dialogViewController))confirmAction cancelAction:(void (^__nullable)(__kindof QMUIDialogViewController *dialogViewController))cancelAction {
-
- QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
- dialogViewController.headerSeparatorColor = nil;
- dialogViewController.view.layer.cornerRadius = 12.f;
- dialogViewController.headerViewBackgroundColor = UIColor.whiteColor;
-
- CGFloat textHeight = [message heightForFont:RQRegularFont_16 width:RQ_SCREEN_WIDTH - 80.f - 32.f] + 16 > RQ_SCREEN_HEIGHT / 2.f? RQ_SCREEN_HEIGHT / 2.f : [message heightForFont:RQRegularFont_16 width:RQ_SCREEN_WIDTH - 80.f - 32.f] + 16;
- dialogViewController.headerViewHeight = (alertType == RQAlertType_Default)? (24.f + 22.f + 16.f + textHeight + 16.f) : 180.f;
-
- NSString *headerImageName = @"";
- CGSize headerImageSize = CGSizeZero;
- switch (alertType) {
- case RQAlertType_Rignt:
- headerImageName = @"正确";
- headerImageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 71.f));
- break;
- case RQAlertType_Warn:
- headerImageName = @"提示";
- headerImageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 64.f));
- break;
- case RQAlertType_Error:
- headerImageName = @"错误";
- headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (277.f / 117.f));
- break;
- case RQAlertType_AD:
- headerImageName = @"激励广告";
- headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (290.f / 136.f));
- break;
-
- default:
- break;
- }
-
- UIImageView *headerIconImageView = [[UIImageView alloc] initWithImage:RQImageNamed(headerImageName)];
- headerIconImageView.contentMode = UIViewContentModeScaleAspectFill;
- if (RQStringIsNotEmpty(headerImageName)) {
- [dialogViewController.headerView addSubview:headerIconImageView];
- [headerIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset((alertType == RQAlertType_Error || alertType == RQAlertType_AD)? 0 : 40);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(headerImageSize);
- }];
- }
-
-
- QMUILabel *titleLabel = [[QMUILabel alloc] qmui_initWithFont:RQSemiboldFont(20) textColor:[UIColor qmui_colorWithHexString:@"#040B26"]];
- titleLabel.text = title;
- titleLabel.textAlignment = NSTextAlignmentCenter;
- [dialogViewController.headerView addSubview:titleLabel];
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(RQStringIsNotEmpty(headerImageName)? headerIconImageView.mas_bottom : dialogViewController.headerView.mas_top).mas_offset(24);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f, 22.f));
- }];
-
- QMUILabel *messageLabel = [[QMUILabel alloc] qmui_initWithFont:RQRegularFont_16 textColor:[UIColor qmui_colorWithHexString:@"#5C6066"]];
- NSMutableAttributedString *mutAttrStr = [[NSMutableAttributedString alloc] initWithString:message];
- if ([message containsString:@"永久删除"]) {
- [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"永久删除"]];
- }
- if ([message containsString:@"VIP用户的VIP权益也将失效"]) {
- [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"VIP用户的VIP权益也将失效"]];
- }
- if (alertType == RQAlertType_SignOut) {
- messageLabel.attributedText = mutAttrStr;
- } else {
- messageLabel.text = message;
- }
-
-
- messageLabel.textAlignment = NSTextAlignmentCenter;
- messageLabel.numberOfLines = 0;
- [dialogViewController.headerView addSubview:messageLabel];
- [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(16);
- make.centerX.mas_offset(0);
- make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f - 32.f, textHeight));
- }];
-
-
- UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - 80.f, 36)];
- contentView.backgroundColor = UIColorWhite;
- dialogViewController.contentView = contentView;
-
- dialogViewController.footerSeparatorColor = nil;
- dialogViewController.footerViewBackgroundColor = UIColor.whiteColor;
- dialogViewController.footerViewHeight = (alertType == RQAlertType_AD)? (40.f + 16.f + 40.f + 30.f) : 84.f;
- dialogViewController.footerView.hidden = NO;
- CGFloat btnWidth = (RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16) / 2.f;
-
- QMUIButton *cancleBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
- [cancleBtn setTitle:cancelTitle textColor:(alertType == RQAlertType_AD)? UIColor.whiteColor : [UIColor qmui_colorWithHexString:@"#5C6066"] Font:15 fotState:UIControlStateNormal];
- cancleBtn.layer.borderColor = [UIColor qmui_colorWithHexString:@"#5C6066"].CGColor;
- cancleBtn.layer.borderWidth = (alertType == RQAlertType_AD)? 0 : 1;
- [cancleBtn setBackgroundImage:[UIImage qmui_imageWithColor:(alertType == RQAlertType_AD)? RQ_MAIN_COLOR : UIColor.whiteColor size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
- cancleBtn.layer.cornerRadius = 20;
- cancleBtn.layer.masksToBounds = YES;
- [cancleBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
- [dialogViewController hide];
- if (cancelAction) {
- cancelAction(dialogViewController);
- }
- }];
-
- if (RQStringIsNotEmpty(cancelTitle)) {
- [dialogViewController.footerView addSubview:cancleBtn];
- if (alertType == RQAlertType_AD) {
- [cancleBtn setImage:RQImageNamed(cancelTitle) forState:UIControlStateNormal];
- cancleBtn.spacingBetweenImageAndTitle = 8.f;
- [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(0);
- make.left.mas_offset(16);
- make.right.mas_offset(-16);
- make.size.mas_equalTo(CGSizeMake((RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16), 40.f));
- }];
- } else {
- [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(0);
- make.left.mas_offset(16);
- make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
- }];
- }
- }
-
-
-
- QMUIButton *confirmBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
- [confirmBtn setTitle:confirmTitle textColor:UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
- [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:(alertType == RQAlertType_AD)? RQColorFromHexString(@"#FFA316") : RQ_MAIN_COLOR size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
- [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:[UIColor qmui_colorWithHexString:@"#8A9099"] size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateDisabled];
- confirmBtn.layer.cornerRadius = 20;
- confirmBtn.layer.masksToBounds = YES;
- [confirmBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
- [dialogViewController hide];
- if (confirmAction) {
- confirmAction(dialogViewController);
- }
- }];
-
- [dialogViewController.footerView addSubview:confirmBtn];
- if (RQStringIsNotEmpty(confirmTitle)) {
- if (alertType == RQAlertType_AD) {
- [confirmBtn setImage:RQImageNamed(confirmTitle) forState:UIControlStateNormal];
- confirmBtn.spacingBetweenImageAndTitle = 8.f;
- [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(cancleBtn.mas_bottom).mas_offset(16.f);
- make.left.mas_offset(16.f);
- make.right.mas_offset(- 16.f);
- make.size.mas_equalTo(CGSizeMake((RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16), 40.f));
- }];
- } else {
- if (RQStringIsNotEmpty(cancelTitle)) {
- [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(0);
- make.right.mas_offset(-16);
- make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
- }];
- } else {
- [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(0);
- make.centerX.mas_offset(0.f);
- make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
- }];
- }
- }
- } else {
- [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(0);
- make.centerX.mas_offset(0.f);
- make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
- }];
- }
-
- if (alertType == RQAlertType_SignOut) {
- [confirmBtn setEnabled:!(alertType == RQAlertType_SignOut)];
-
- __block NSInteger customIndex = 11;
- [[[RACSignal interval:1 onScheduler:[RACScheduler mainThreadScheduler]] take:customIndex] subscribeNext:^(id x) {
- customIndex --;
- [confirmBtn setTitleNormal:[NSString stringWithFormat:@"%@(%lds)",confirmTitle,customIndex]];
- [confirmBtn setEnabled:customIndex <= 0];
- if (customIndex <= 0) {
- [confirmBtn setTitleNormal:confirmTitle];
- }
- }];
- }
-
- if (alertType == RQAlertType_AD) {
- QMUIButton *closeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
- [closeBtn setBackgroundImage:RQImageNamed(@"关闭") forState:UIControlStateNormal];
- [dialogViewController.headerView addSubview:closeBtn];
- [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_offset(16.f);
- make.right.mas_offset(-16.f);
- make.size.mas_equalTo(CGSizeMake(36.f, 36.f));
- }];
- [closeBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
- [dialogViewController hide];
- }];
- }
-
- [dialogViewController show];
- }
- @end
|