RQAlertViewManager.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. //
  2. // RQAlertViewManager.m
  3. // SDJK
  4. //
  5. // Created by 张嵘 on 2021/8/17.
  6. //
  7. #import "RQAlertViewManager.h"
  8. @interface RQAlertViewManager ()
  9. @property (nonatomic, readwrite, strong) SCLAlertView *alert;
  10. @property (nonatomic, readwrite, strong) UITextView *messageTextView;
  11. @property (nonatomic, readwrite, strong) SCLButton *rePlayButton;
  12. @property (nonatomic, readwrite, strong) SCLButton *closeButton;
  13. @property (nonatomic, readwrite, assign) BOOL isShow;
  14. @end
  15. @implementation RQAlertViewManager
  16. @def_singleton(RQAlertViewManager);
  17. - (void)rq_showOfficialInterpretationAlertWithMessage:(NSString *)messageStr mp3Url:(NSString *)mp3Url {
  18. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
  19. @weakify(alert)
  20. CGFloat viewTextWideth = RQ_SCREEN_WIDTH - (20 * 2) - (40 * 2);
  21. 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];
  22. RQTrack *track = [[RQTrack alloc] init];
  23. track.audioFileURL = [NSURL URLWithString:mp3Url];
  24. RQ_MUSIC_MANAGER.audioTrack = track;
  25. [alert removeTopCircle];
  26. alert.tintTopCircle = NO;
  27. alert.useLargerIcon = NO;
  28. alert.iconTintColor = RQ_MAIN_COLOR;
  29. alert.cornerRadius = 10;
  30. alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
  31. alert.labelTitle.font = [UIFont boldSystemFontOfSize:15];
  32. [alert.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.mas_offset(20);
  34. make.centerX.mas_offset(0);
  35. make.size.mas_equalTo(CGSizeMake(viewTextWideth, 21.f));
  36. }];
  37. UITextView *messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, alert.labelTitle.rq_y + alert.labelTitle.rq_height, viewTextWideth, textHeight)];
  38. messageTextView.font = [UIFont systemFontOfSize:13];
  39. messageTextView.editable = NO;
  40. messageTextView.textColor = RQ_MAIN_TEXT_COLOR_3;
  41. messageTextView.textAlignment = NSTextAlignmentLeft;
  42. messageTextView.text = messageStr;
  43. [alert addCustomView:messageTextView];
  44. [messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.top.mas_equalTo(alert.labelTitle.mas_bottom).mas_offset(20);
  46. make.centerX.mas_offset(0);
  47. make.size.mas_equalTo(CGSizeMake(viewTextWideth, textHeight)).priority(500);
  48. }];
  49. SCLButton *closeButton = [alert addButton:@"关闭" actionBlock:^{
  50. @strongify(alert);
  51. [alert hideView];
  52. [RQ_MUSIC_MANAGER rq_cancelStreamer];
  53. }];
  54. closeButton.buttonFormatBlock = ^NSDictionary* (void) {
  55. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  56. buttonConfig[@"cornerRadius"] = @"15.f";
  57. buttonConfig[@"backgroundColor"] = RQ_MAIN_BACKGROUNDCOLOR;
  58. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_3;
  59. buttonConfig[@"borderWidth"] = @1.0f;
  60. buttonConfig[@"borderColor"] = RQ_MAIN_TEXT_COLOR_3;
  61. buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
  62. return buttonConfig;
  63. };
  64. [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.mas_equalTo(messageTextView.mas_bottom).mas_offset(20);
  66. make.left.mas_equalTo(messageTextView.mas_left);
  67. make.bottom.mas_offset(-20);
  68. make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 30.f));
  69. }];
  70. SCLButton *rePlayButton = [alert addButton:@"语音重播" validationBlock:^BOOL{
  71. [RQ_MUSIC_MANAGER rq_resetStreamer];
  72. return NO;
  73. } actionBlock:nil];
  74. rePlayButton.buttonFormatBlock = ^NSDictionary* (void) {
  75. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  76. buttonConfig[@"cornerRadius"] = @"15.f";
  77. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  78. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  79. buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
  80. return buttonConfig;
  81. };
  82. [rePlayButton mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.right.mas_equalTo(messageTextView.mas_right);
  84. make.bottom.mas_offset(-20);
  85. make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 30.f));
  86. }];
  87. alert.horizontalButtons = YES;
  88. alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
  89. [alert showTitle:@"官方解释" subTitle:nil style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
  90. [RQ_MUSIC_MANAGER rq_resetStreamer];
  91. }
  92. - (void)rq_showSkillExplanationAlertWithMessage:(NSString *)messageStr skillkeyword:(NSString *)skillkeyword explainGifUrl:(NSString *)explainGifUrl mp3Url:(NSString *)mp3Url completeBlock:(void(^__nullable)(void))completeBlock {
  93. if (_isShow) {
  94. return;
  95. }
  96. self.messageTextView = nil;
  97. self.alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
  98. [_alert removeTopCircle];
  99. _alert.tintTopCircle = NO;
  100. _alert.useLargerIcon = NO;
  101. _alert.iconTintColor = RQ_MAIN_COLOR;
  102. _alert.cornerRadius = 10;
  103. _alert.horizontalButtons = YES;
  104. _alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
  105. _alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
  106. _alert.labelTitle.font = [UIFont boldSystemFontOfSize:15];
  107. CGFloat viewTextWideth = RQ_SCREEN_WIDTH - (20 * 2) - (40 * 2);
  108. 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];
  109. RQTrack *track = [[RQTrack alloc] init];
  110. track.audioFileURL = [NSURL URLWithString:mp3Url];
  111. RQ_MUSIC_MANAGER.audioTrack = track;
  112. [self.alert.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.top.mas_offset(20);
  114. make.centerX.mas_offset(0);
  115. make.size.mas_equalTo(CGSizeMake(viewTextWideth, 21.f));
  116. }];
  117. UIImageView *gifImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_alert.labelTitle.rq_x, _alert.labelTitle.rq_y + _alert.labelTitle.rq_height, viewTextWideth, viewTextWideth * 0.5)];
  118. [gifImageView sd_setImageWithURL:[NSURL URLWithString:explainGifUrl] placeholderImage:RQWebImagePlaceholder()];
  119. if (RQStringIsNotEmpty(explainGifUrl)) {
  120. [_alert addCustomView:gifImageView];
  121. [gifImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.top.mas_equalTo(_alert.labelTitle.mas_bottom).mas_offset(20);
  123. make.centerX.mas_offset(0);
  124. make.size.mas_equalTo(CGSizeMake(viewTextWideth, viewTextWideth * 0.5));
  125. }];
  126. }
  127. if (RQStringIsNotEmpty(messageStr)) {
  128. 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)];
  129. textViewTitleLabel.text = @"本题速记口诀";
  130. textViewTitleLabel.textColor = RQ_MAIN_TEXT_COLOR_1;
  131. textViewTitleLabel.font = [UIFont systemFontOfSize:13];
  132. textViewTitleLabel.textAlignment = NSTextAlignmentCenter;
  133. [_alert addCustomView:textViewTitleLabel];
  134. [textViewTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.top.mas_equalTo(RQStringIsNotEmpty(explainGifUrl)? gifImageView.mas_bottom : _alert.labelTitle.mas_bottom).mas_offset(20);
  136. make.centerX.mas_offset(0);
  137. make.size.mas_equalTo(CGSizeMake(88, 18));
  138. }];
  139. UIImageView *leftLineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 1)];
  140. leftLineImageView.backgroundColor = RQ_MAIN_TEXT_COLOR_5;
  141. [_alert addCustomView:leftLineImageView];
  142. [leftLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  143. make.centerY.mas_equalTo(textViewTitleLabel);
  144. make.right.mas_equalTo(textViewTitleLabel.mas_left).mas_offset(- 5);
  145. make.size.mas_equalTo(CGSizeMake(20, 1));
  146. }];
  147. UIImageView *rightLineImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 1)];
  148. rightLineImageView.backgroundColor = RQ_MAIN_TEXT_COLOR_5;
  149. [_alert addCustomView:rightLineImageView];
  150. [rightLineImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  151. make.centerY.mas_equalTo(textViewTitleLabel);
  152. make.left.mas_equalTo(textViewTitleLabel.mas_right).mas_offset(5);
  153. make.size.mas_equalTo(CGSizeMake(20, 1));
  154. }];
  155. self.messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(_alert.labelTitle.rq_x, textViewTitleLabel.rq_y + textViewTitleLabel.rq_height, viewTextWideth, textHeight)];
  156. self.messageTextView.font = [UIFont systemFontOfSize:13];
  157. self.messageTextView.editable = NO;
  158. self.messageTextView.textColor = RQ_MAIN_TEXT_COLOR_3;
  159. self.messageTextView.textAlignment = NSTextAlignmentLeft;
  160. [_alert addCustomView:self.messageTextView];
  161. if (RQStringIsNotEmpty(skillkeyword)) {
  162. NSMutableAttributedString *abs = [[NSMutableAttributedString alloc] initWithString:messageStr? : @""];
  163. [[[skillkeyword componentsSeparatedByString:@"-"].rac_sequence.signal deliverOnMainThread] subscribeNext:^(NSString * _Nullable skillkeywordStr) {
  164. NSRange targetRange = NSMakeRange(0, messageStr.length);
  165. NSRange range = targetRange;
  166. while (true) {
  167. range = [messageStr rangeOfString:skillkeywordStr options:NSLiteralSearch range:targetRange];
  168. if (range.location != NSNotFound) {
  169. NSRange newRange = NSMakeRange(range.location - 1, range.length + 2);
  170. NSString *keywordStr = [messageStr substringWithRange:newRange];
  171. if ([keywordStr containsString:@"“"] || [keywordStr containsString:@"”"] || [keywordStr containsString:@"\""]) {
  172. range = newRange;
  173. }
  174. targetRange = NSMakeRange(NSMaxRange(range), messageStr.length-NSMaxRange(range));
  175. [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:range];
  176. [abs addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:targetRange];
  177. [abs addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:range];
  178. } else {
  179. break;
  180. }
  181. }
  182. } completed:^{
  183. self.messageTextView.attributedText = abs;
  184. }];
  185. } else {
  186. self.messageTextView.text = messageStr;
  187. }
  188. [self.messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  189. make.top.mas_equalTo(textViewTitleLabel.mas_bottom).mas_offset(15);
  190. make.centerX.mas_offset(0);
  191. make.size.mas_equalTo(CGSizeMake(viewTextWideth, textHeight)).priority(500);
  192. }];
  193. }
  194. @weakify(self)
  195. self.closeButton = [self.alert addButton:@"关闭" actionBlock:^{
  196. @strongify(self);
  197. if (RQ_COMMON_MANAGER.isAutoRead) {
  198. completeBlock();
  199. }
  200. [self.alert hideView];
  201. _isShow = NO;
  202. [RQ_COMMON_MANAGER cancleAutoReadQuestion];
  203. }];
  204. self.closeButton.buttonFormatBlock = ^NSDictionary* (void) {
  205. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  206. buttonConfig[@"cornerRadius"] = @"15.f";
  207. buttonConfig[@"backgroundColor"] = RQ_MAIN_BACKGROUNDCOLOR;
  208. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_3;
  209. buttonConfig[@"borderWidth"] = @1.0f;
  210. buttonConfig[@"borderColor"] = RQ_MAIN_TEXT_COLOR_3;
  211. buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
  212. return buttonConfig;
  213. };
  214. [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  215. if (self.messageTextView) {
  216. make.top.mas_equalTo(self.messageTextView.mas_bottom).mas_offset(20);
  217. } else {
  218. make.top.mas_equalTo(RQStringIsNotEmpty(explainGifUrl)? gifImageView.mas_bottom : _alert.labelTitle.mas_bottom).mas_offset(20);
  219. }
  220. make.left.mas_equalTo(_alert.labelTitle.mas_left);
  221. make.bottom.mas_offset(-20);
  222. make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 30.f));
  223. }];
  224. self.rePlayButton = [self.alert addButton:@"语音重播" validationBlock:^BOOL{
  225. [RQ_MUSIC_MANAGER rq_resetStreamer];
  226. return NO;
  227. } actionBlock:nil];
  228. self.rePlayButton.buttonFormatBlock = ^NSDictionary* (void) {
  229. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  230. buttonConfig[@"cornerRadius"] = @"15.f";
  231. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  232. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  233. buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
  234. return buttonConfig;
  235. };
  236. [self.rePlayButton mas_makeConstraints:^(MASConstraintMaker *make) {
  237. make.right.mas_equalTo(_alert.labelTitle.mas_right);
  238. make.bottom.mas_offset(-20);
  239. make.size.mas_equalTo(CGSizeMake((viewTextWideth - 16) / 2.f, 30.f));
  240. }];
  241. [_alert showTitle:@"技巧讲解" subTitle:nil style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
  242. _isShow = YES;
  243. if (RQ_COMMON_MANAGER.isAutoRead) {
  244. [RQ_MUSIC_MANAGER rq_resetStreamerWithDOUAudioStreamerStatusBlock:^(DOUAudioStreamerStatus status) {
  245. if (status == DOUAudioStreamerFinished) {
  246. completeBlock();
  247. [_alert hideView];
  248. _isShow = NO;
  249. }
  250. }];
  251. } else {
  252. [RQ_MUSIC_MANAGER rq_resetStreamer];
  253. }
  254. }
  255. - (void)rq_ActivateVIPAlertWithComplete:(VoidBlock_Bool)complete {
  256. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
  257. @weakify(alert)
  258. [alert removeTopCircle];
  259. alert.tintTopCircle = NO;
  260. alert.useLargerIcon = NO;
  261. alert.shouldDismissOnTapOutside = YES;
  262. alert.iconTintColor = RQ_MAIN_COLOR;
  263. alert.cornerRadius = 10;
  264. alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
  265. alert.labelTitle.font = [UIFont boldSystemFontOfSize:15];
  266. UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 250, 30)];
  267. textFiled.borderStyle = UITextBorderStyleNone;
  268. textFiled.backgroundColor = RQ_LIST_BACKGROUNDCOLOR;
  269. textFiled.layer.cornerRadius = 15;
  270. textFiled.layer.borderWidth = 1;
  271. textFiled.layer.borderColor = RQ_MAIN_LINE_COLOR_1.CGColor;
  272. textFiled.clipsToBounds = YES;
  273. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
  274. UIImageView *imageView = [[UIImageView alloc]initWithImage:RQImageNamed(@"activationIcon")];
  275. imageView.center = leftView.center;
  276. [leftView addSubview:imageView];
  277. textFiled.leftView = imageView;
  278. textFiled.leftViewMode = UITextFieldViewModeAlways; //此处用来设置leftview现实时机
  279. textFiled.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  280. textFiled.placeholder = @"请输入激活码";
  281. textFiled.tintColor = [UIColor colorWithHexString:@"#BFBFBF"];
  282. textFiled.textColor = RQ_MAIN_TEXT_COLOR_3;
  283. textFiled.font = [UIFont systemFontOfSize:13];
  284. [alert addCustomTextField:textFiled];
  285. SCLButton *closeButton = [alert addButton:@"" actionBlock:^{
  286. @strongify(alert);
  287. [alert hideView];
  288. if (complete) {
  289. complete(NO);
  290. }
  291. }];
  292. [closeButton setImage:RQImageNamed(@"close") forState:UIControlStateNormal];
  293. [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  294. make.top.mas_offset(14);
  295. make.right.mas_offset(-14);
  296. make.size.mas_equalTo(CGSizeMake(16.f, 16.f));
  297. }];
  298. SCLButton *activateBtn = [alert addButton:@"立即开通" validationBlock:^BOOL{
  299. if (textFiled.text.length <= 0) {
  300. [MBProgressHUD rq_showTips:@"请输入激活码"];
  301. }
  302. return textFiled.text.length > 0;
  303. } actionBlock:^{
  304. if (complete) {
  305. complete(YES);
  306. }
  307. }];
  308. activateBtn.buttonFormatBlock = ^NSDictionary* (void) {
  309. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  310. buttonConfig[@"cornerRadius"] = @"15.f";
  311. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  312. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  313. buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
  314. return buttonConfig;
  315. };
  316. [activateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  317. make.centerX.mas_offset(0);
  318. make.bottom.mas_offset(-20);
  319. make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(100.f), 30.f));
  320. }];
  321. alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
  322. [alert showTitle:@"提示" subTitle:@"您还未开通系统,请输入激活码开通!" style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
  323. }
  324. /**
  325. 弹出alertController,并且有两个个action按钮,分别有处理事件
  326. @param alertType 弹窗类型
  327. @param title title
  328. @param message Message
  329. @param confirmTitle 左边按钮的title
  330. @param cancelTitle 右边按钮的title
  331. @param confirmAction 左边按钮的点击事件
  332. @param cancelAction 右按钮的点击事件
  333. */
  334. - (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 {
  335. QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
  336. dialogViewController.headerSeparatorColor = nil;
  337. dialogViewController.view.layer.cornerRadius = 12.f;
  338. dialogViewController.headerViewBackgroundColor = UIColor.whiteColor;
  339. 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;
  340. dialogViewController.headerViewHeight = (alertType == RQAlertType_Default)? (24.f + 22.f + 16.f + textHeight + 16.f) : 180.f;
  341. NSString *headerImageName = @"";
  342. CGSize headerImageSize = CGSizeZero;
  343. switch (alertType) {
  344. case RQAlertType_Rignt:
  345. headerImageName = @"正确";
  346. headerImageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 71.f));
  347. break;
  348. case RQAlertType_Warn:
  349. headerImageName = @"提示";
  350. headerImageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 64.f));
  351. break;
  352. case RQAlertType_Error:
  353. headerImageName = @"错误";
  354. headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (277.f / 117.f));
  355. break;
  356. case RQAlertType_AD:
  357. headerImageName = @"激励广告";
  358. headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (290.f / 136.f));
  359. break;
  360. default:
  361. break;
  362. }
  363. UIImageView *headerIconImageView = [[UIImageView alloc] initWithImage:RQImageNamed(headerImageName)];
  364. headerIconImageView.contentMode = UIViewContentModeScaleAspectFill;
  365. if (RQStringIsNotEmpty(headerImageName)) {
  366. [dialogViewController.headerView addSubview:headerIconImageView];
  367. [headerIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  368. make.top.mas_offset((alertType == RQAlertType_Error || alertType == RQAlertType_AD)? 0 : 40);
  369. make.centerX.mas_offset(0);
  370. make.size.mas_equalTo(headerImageSize);
  371. }];
  372. }
  373. QMUILabel *titleLabel = [[QMUILabel alloc] qmui_initWithFont:RQSemiboldFont(20) textColor:[UIColor qmui_colorWithHexString:@"#040B26"]];
  374. titleLabel.text = title;
  375. titleLabel.textAlignment = NSTextAlignmentCenter;
  376. [dialogViewController.headerView addSubview:titleLabel];
  377. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  378. make.top.mas_equalTo(RQStringIsNotEmpty(headerImageName)? headerIconImageView.mas_bottom : dialogViewController.headerView.mas_top).mas_offset(24);
  379. make.centerX.mas_offset(0);
  380. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f, 22.f));
  381. }];
  382. QMUILabel *messageLabel = [[QMUILabel alloc] qmui_initWithFont:RQRegularFont_16 textColor:[UIColor qmui_colorWithHexString:@"#5C6066"]];
  383. NSMutableAttributedString *mutAttrStr = [[NSMutableAttributedString alloc] initWithString:message];
  384. if ([message containsString:@"永久删除"]) {
  385. [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"永久删除"]];
  386. }
  387. if ([message containsString:@"VIP用户的VIP权益也将失效"]) {
  388. [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"VIP用户的VIP权益也将失效"]];
  389. }
  390. if (alertType == RQAlertType_SignOut) {
  391. messageLabel.attributedText = mutAttrStr;
  392. } else {
  393. messageLabel.text = message;
  394. }
  395. messageLabel.textAlignment = NSTextAlignmentCenter;
  396. messageLabel.numberOfLines = 0;
  397. [dialogViewController.headerView addSubview:messageLabel];
  398. [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  399. make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(16);
  400. make.centerX.mas_offset(0);
  401. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f - 32.f, textHeight));
  402. }];
  403. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - 80.f, 36)];
  404. contentView.backgroundColor = UIColorWhite;
  405. dialogViewController.contentView = contentView;
  406. dialogViewController.footerSeparatorColor = nil;
  407. dialogViewController.footerViewBackgroundColor = UIColor.whiteColor;
  408. dialogViewController.footerViewHeight = (alertType == RQAlertType_AD)? (40.f + 16.f + 40.f + 30.f) : 84.f;
  409. dialogViewController.footerView.hidden = NO;
  410. CGFloat btnWidth = (RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16) / 2.f;
  411. QMUIButton *cancleBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  412. [cancleBtn setTitle:cancelTitle textColor:(alertType == RQAlertType_AD)? UIColor.whiteColor : [UIColor qmui_colorWithHexString:@"#5C6066"] Font:15 fotState:UIControlStateNormal];
  413. cancleBtn.layer.borderColor = [UIColor qmui_colorWithHexString:@"#5C6066"].CGColor;
  414. cancleBtn.layer.borderWidth = (alertType == RQAlertType_AD)? 0 : 1;
  415. [cancleBtn setBackgroundImage:[UIImage qmui_imageWithColor:(alertType == RQAlertType_AD)? RQ_MAIN_COLOR : UIColor.whiteColor size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
  416. cancleBtn.layer.cornerRadius = 20;
  417. cancleBtn.layer.masksToBounds = YES;
  418. [cancleBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  419. [dialogViewController hide];
  420. if (cancelAction) {
  421. cancelAction(dialogViewController);
  422. }
  423. }];
  424. if (RQStringIsNotEmpty(cancelTitle)) {
  425. [dialogViewController.footerView addSubview:cancleBtn];
  426. if (alertType == RQAlertType_AD) {
  427. [cancleBtn setImage:RQImageNamed(cancelTitle) forState:UIControlStateNormal];
  428. cancleBtn.spacingBetweenImageAndTitle = 8.f;
  429. [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  430. make.top.mas_offset(0);
  431. make.left.mas_offset(16);
  432. make.right.mas_offset(-16);
  433. make.size.mas_equalTo(CGSizeMake((RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16), 40.f));
  434. }];
  435. } else {
  436. [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  437. make.top.mas_offset(0);
  438. make.left.mas_offset(16);
  439. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  440. }];
  441. }
  442. }
  443. QMUIButton *confirmBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  444. [confirmBtn setTitle:confirmTitle textColor:UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
  445. [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:(alertType == RQAlertType_AD)? RQColorFromHexString(@"#FFA316") : RQ_MAIN_COLOR size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
  446. [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:[UIColor qmui_colorWithHexString:@"#8A9099"] size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateDisabled];
  447. confirmBtn.layer.cornerRadius = 20;
  448. confirmBtn.layer.masksToBounds = YES;
  449. [confirmBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  450. [dialogViewController hide];
  451. if (confirmAction) {
  452. confirmAction(dialogViewController);
  453. }
  454. }];
  455. [dialogViewController.footerView addSubview:confirmBtn];
  456. if (RQStringIsNotEmpty(confirmTitle)) {
  457. if (alertType == RQAlertType_AD) {
  458. [confirmBtn setImage:RQImageNamed(confirmTitle) forState:UIControlStateNormal];
  459. confirmBtn.spacingBetweenImageAndTitle = 8.f;
  460. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  461. make.top.mas_equalTo(cancleBtn.mas_bottom).mas_offset(16.f);
  462. make.left.mas_offset(16.f);
  463. make.right.mas_offset(- 16.f);
  464. make.size.mas_equalTo(CGSizeMake((RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16), 40.f));
  465. }];
  466. } else {
  467. if (RQStringIsNotEmpty(cancelTitle)) {
  468. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  469. make.top.mas_offset(0);
  470. make.right.mas_offset(-16);
  471. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  472. }];
  473. } else {
  474. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  475. make.top.mas_offset(0);
  476. make.centerX.mas_offset(0.f);
  477. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  478. }];
  479. }
  480. }
  481. } else {
  482. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  483. make.top.mas_offset(0);
  484. make.centerX.mas_offset(0.f);
  485. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  486. }];
  487. }
  488. if (alertType == RQAlertType_SignOut) {
  489. [confirmBtn setEnabled:!(alertType == RQAlertType_SignOut)];
  490. __block NSInteger customIndex = 11;
  491. [[[RACSignal interval:1 onScheduler:[RACScheduler mainThreadScheduler]] take:customIndex] subscribeNext:^(id x) {
  492. customIndex --;
  493. [confirmBtn setTitleNormal:[NSString stringWithFormat:@"%@(%lds)",confirmTitle,customIndex]];
  494. [confirmBtn setEnabled:customIndex <= 0];
  495. if (customIndex <= 0) {
  496. [confirmBtn setTitleNormal:confirmTitle];
  497. }
  498. }];
  499. }
  500. if (alertType == RQAlertType_AD) {
  501. QMUIButton *closeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  502. [closeBtn setBackgroundImage:RQImageNamed(@"关闭") forState:UIControlStateNormal];
  503. [dialogViewController.headerView addSubview:closeBtn];
  504. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  505. make.top.mas_offset(16.f);
  506. make.right.mas_offset(-16.f);
  507. make.size.mas_equalTo(CGSizeMake(36.f, 36.f));
  508. }];
  509. [closeBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  510. [dialogViewController hide];
  511. }];
  512. }
  513. [dialogViewController show];
  514. }
  515. @end