RQAlertViewManager.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. //
  2. // RQAlertViewManager.m
  3. // JSJP
  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. /**
  18. 弹出alertController,并且有两个个action按钮,分别有处理事件
  19. @param title title
  20. @param message Message
  21. @param confirmTitle 左边按钮的title
  22. @param confirmAction 左边按钮的点击事件
  23. */
  24. - (void)showAlertWithTitle:(NSString * _Nullable )title message:(NSString * _Nullable )message confirmTitle:(NSString *)confirmTitle confirmAction:(void (^__nullable)(__kindof QMUIDialogViewController *dialogViewController))confirmAction {
  25. [self showAlertWithAlertType:RQAlertType_Default title:title message:message confirmTitle:confirmTitle cancelTitle:nil confirmAction:confirmAction cancelAction:nil];
  26. }
  27. /**
  28. 弹出alertController,并且有两个个action按钮,分别有处理事件
  29. @param alertType 弹窗类型
  30. @param title title
  31. @param message Message
  32. @param confirmTitle 左边按钮的title
  33. @param cancelTitle 右边按钮的title
  34. @param confirmAction 左边按钮的点击事件
  35. @param cancelAction 右按钮的点击事件
  36. */
  37. - (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 {
  38. QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
  39. dialogViewController.headerSeparatorColor = nil;
  40. dialogViewController.view.layer.cornerRadius = 12.f;
  41. dialogViewController.headerViewBackgroundColor = UIColor.whiteColor;
  42. 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;
  43. if(alertType == RQAlertType_Default){
  44. dialogViewController.headerViewHeight = (24.f + 22.f + 16.f + textHeight + 16.f) ;
  45. }else if(alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG){
  46. dialogViewController.headerViewHeight = (140.f + textHeight ) ;
  47. }else{
  48. dialogViewController.headerViewHeight = 180.f;
  49. }
  50. // dialogViewController.headerViewHeight = (alertType == RQAlertType_Default)? (24.f + 22.f + 16.f + textHeight + 16.f) : 180.f;
  51. NSString *headerImageName = @"";
  52. CGSize headerImageSize = CGSizeZero;
  53. switch (alertType) {
  54. case RQAlertType_Rignt:
  55. headerImageName = @"正确";
  56. headerImageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 71.f));
  57. break;
  58. case RQAlertType_Warn:
  59. headerImageName = @"提示";
  60. headerImageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 64.f));
  61. break;
  62. case RQAlertType_Error:
  63. headerImageName = @"错误";
  64. headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (277.f / 117.f));
  65. break;
  66. case RQAlertType_AD:
  67. headerImageName = @"激励广告";
  68. headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (290.f / 136.f));
  69. break;
  70. case RQAlertType_AD_MI:
  71. headerImageName = @"mijuan背景";
  72. headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (290.f / 136.f));
  73. break;
  74. case RQAlertType_AD_SONG:
  75. headerImageName = @"tesu_song背景";
  76. headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (290.f / 136.f));
  77. break;
  78. default:
  79. break;
  80. }
  81. UIImageView *headerIconImageView = [[UIImageView alloc] initWithImage:RQImageNamed(headerImageName)];
  82. headerIconImageView.contentMode = UIViewContentModeScaleAspectFill;
  83. if (RQStringIsNotEmpty(headerImageName)) {
  84. [dialogViewController.headerView addSubview:headerIconImageView];
  85. [headerIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.top.mas_offset((alertType == RQAlertType_Error || alertType == RQAlertType_AD|| alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG)? 0 : 40);
  87. make.centerX.mas_offset(0);
  88. make.size.mas_equalTo(headerImageSize);
  89. }];
  90. }
  91. QMUILabel *titleLabel = [[QMUILabel alloc] qmui_initWithFont:RQSemiboldFont(20) textColor:[UIColor qmui_colorWithHexString:@"#040B26"]];
  92. titleLabel.text = title;
  93. titleLabel.textAlignment = NSTextAlignmentCenter;
  94. [dialogViewController.headerView addSubview:titleLabel];
  95. if (alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG) {
  96. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.top.mas_equalTo(RQStringIsNotEmpty(headerImageName)? headerIconImageView.mas_bottom : dialogViewController.headerView.mas_top).mas_offset(24);
  98. make.centerX.mas_offset(0);
  99. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f, 0));
  100. }];
  101. }else{
  102. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.top.mas_equalTo(RQStringIsNotEmpty(headerImageName)? headerIconImageView.mas_bottom : dialogViewController.headerView.mas_top).mas_offset(24);
  104. make.centerX.mas_offset(0);
  105. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f, 22.f));
  106. }];
  107. }
  108. QMUILabel *messageLabel = [[QMUILabel alloc] qmui_initWithFont:RQRegularFont_16 textColor:[UIColor qmui_colorWithHexString:@"#5C6066"]];
  109. NSMutableAttributedString *mutAttrStr = [[NSMutableAttributedString alloc] initWithString:message];
  110. if ([message containsString:@"永久删除"]) {
  111. [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"永久删除"]];
  112. }
  113. if ([message containsString:@"VIP用户的VIP权益也将失效"]) {
  114. [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"VIP用户的VIP权益也将失效"]];
  115. }
  116. if (alertType == RQAlertType_SignOut) {
  117. messageLabel.attributedText = mutAttrStr;
  118. } else {
  119. messageLabel.text = message;
  120. }
  121. messageLabel.textAlignment = NSTextAlignmentCenter;
  122. messageLabel.numberOfLines = 0;
  123. [dialogViewController.headerView addSubview:messageLabel];
  124. if (alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG) {
  125. [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(-10);
  127. make.centerX.mas_offset(0);
  128. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f - 32.f, textHeight));
  129. }];
  130. }else{
  131. [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  132. make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(16);
  133. make.centerX.mas_offset(0);
  134. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f - 32.f, textHeight));
  135. }];
  136. }
  137. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - 80.f, 36)];
  138. contentView.backgroundColor = UIColorWhite;
  139. dialogViewController.contentView = contentView;
  140. dialogViewController.footerSeparatorColor = nil;
  141. dialogViewController.footerViewBackgroundColor = UIColor.whiteColor;
  142. dialogViewController.footerViewHeight = (alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG)? (40.f + 30.f) : 84.f;
  143. dialogViewController.footerView.hidden = NO;
  144. CGFloat btnWidth = (RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16) / 2.f;
  145. QMUIButton *cancleBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  146. [cancleBtn setTitle:cancelTitle textColor:(alertType == RQAlertType_AD)? UIColor.whiteColor : [UIColor qmui_colorWithHexString:@"#5C6066"] Font:15 fotState:UIControlStateNormal];
  147. if(alertType == RQAlertType_AD_SONG){
  148. [cancleBtn setTitle:@"看广告送VIP" textColor:UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
  149. }
  150. cancleBtn.layer.borderColor = [UIColor qmui_colorWithHexString:@"#5C6066"].CGColor;
  151. cancleBtn.layer.borderWidth = (alertType == RQAlertType_AD||alertType == RQAlertType_AD_SONG)? 0 : 1;
  152. [cancleBtn setBackgroundImage:[UIImage qmui_imageWithColor:(alertType == RQAlertType_AD||alertType == RQAlertType_AD_SONG)? RQ_MAIN_COLOR : UIColor.whiteColor size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
  153. cancleBtn.layer.cornerRadius = (alertType == RQAlertType_AD||alertType == RQAlertType_AD_SONG)? 8 : 20;
  154. if(alertType == RQAlertType_AD_MI){
  155. [cancleBtn setTitle:cancelTitle textColor: UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
  156. cancleBtn.layer.borderColor = [UIColor qmui_colorWithHexString:@"#DF1E19"].CGColor;
  157. cancleBtn.layer.borderWidth = 0;
  158. [cancleBtn setBackgroundImage:[UIImage qmui_imageWithColor:[UIColor qmui_colorWithHexString:@"#DF1E19"] size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
  159. cancleBtn.layer.cornerRadius = 8;
  160. }
  161. cancleBtn.layer.masksToBounds = YES;
  162. [cancleBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  163. [dialogViewController hide];
  164. if (cancelAction) {
  165. cancelAction(dialogViewController);
  166. }
  167. }];
  168. if (RQStringIsNotEmpty(cancelTitle)) {
  169. [dialogViewController.footerView addSubview:cancleBtn];
  170. if (alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG) {
  171. [cancleBtn setImage:RQImageNamed(cancelTitle) forState:UIControlStateNormal];
  172. cancleBtn.spacingBetweenImageAndTitle = 8.f;
  173. [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  174. make.top.mas_offset(16);
  175. make.left.mas_offset(16);
  176. // make.right.mas_offset(-16);
  177. make.size.mas_equalTo(CGSizeMake((RQ_SCREEN_WIDTH*0.5- (16 * 3) -16), 40.f));
  178. }];
  179. } else {
  180. [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  181. make.top.mas_offset(0);
  182. make.left.mas_offset(16);
  183. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  184. }];
  185. }
  186. }
  187. QMUIButton *confirmBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  188. [confirmBtn setTitle:confirmTitle textColor:UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
  189. if(alertType == RQAlertType_AD_SONG){
  190. [confirmBtn setTitle:@"土豪充值" textColor:UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
  191. }
  192. [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:(alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG)? RQColorFromHexString(@"#FFA316") : RQ_MAIN_COLOR size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
  193. [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:[UIColor qmui_colorWithHexString:@"#8A9099"] size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateDisabled];
  194. confirmBtn.layer.cornerRadius = (alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG)? 8 : 20;
  195. confirmBtn.layer.masksToBounds = YES;
  196. [confirmBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  197. [dialogViewController hide];
  198. if (confirmAction) {
  199. confirmAction(dialogViewController);
  200. }
  201. }];
  202. [dialogViewController.footerView addSubview:confirmBtn];
  203. if (RQStringIsNotEmpty(confirmTitle)) {
  204. if (alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG) {
  205. [confirmBtn setImage:RQImageNamed(confirmTitle) forState:UIControlStateNormal];
  206. confirmBtn.spacingBetweenImageAndTitle = 8.f;
  207. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.top.mas_offset(16);
  209. // make.top.mas_equalTo(cancleBtn.mas_bottom).mas_offset(16.f);
  210. // make.left.mas_offset(16.f);
  211. make.right.mas_offset(- 16.f);
  212. make.size.mas_equalTo(CGSizeMake((RQ_SCREEN_WIDTH*0.5 - (16 * 3) - 16), 40.f));
  213. }];
  214. } else {
  215. if (RQStringIsNotEmpty(cancelTitle)) {
  216. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  217. make.top.mas_offset(0);
  218. make.right.mas_offset(-16);
  219. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  220. }];
  221. } else {
  222. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  223. make.top.mas_offset(0);
  224. make.centerX.mas_offset(0.f);
  225. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  226. }];
  227. }
  228. }
  229. } else {
  230. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.top.mas_offset(0);
  232. make.centerX.mas_offset(0.f);
  233. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  234. }];
  235. }
  236. if (alertType == RQAlertType_SignOut) {
  237. [confirmBtn setEnabled:!(alertType == RQAlertType_SignOut)];
  238. __block NSInteger customIndex = 11;
  239. [[[RACSignal interval:1 onScheduler:[RACScheduler mainThreadScheduler]] take:customIndex] subscribeNext:^(id x) {
  240. customIndex --;
  241. [confirmBtn setTitleNormal:[NSString stringWithFormat:@"%@(%lds)",confirmTitle,customIndex]];
  242. [confirmBtn setEnabled:customIndex <= 0];
  243. if (customIndex <= 0) {
  244. [confirmBtn setTitleNormal:confirmTitle];
  245. }
  246. }];
  247. }
  248. if (alertType == RQAlertType_AD||alertType == RQAlertType_AD_MI||alertType == RQAlertType_AD_SONG) {
  249. QMUIButton *closeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  250. [closeBtn setBackgroundImage:RQImageNamed(@"关闭") forState:UIControlStateNormal];
  251. [dialogViewController.headerView addSubview:closeBtn];
  252. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  253. make.top.mas_offset(16.f);
  254. make.right.mas_offset(-16.f);
  255. make.size.mas_equalTo(CGSizeMake(36.f, 36.f));
  256. }];
  257. [closeBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  258. [dialogViewController hide];
  259. }];
  260. }
  261. [dialogViewController show];
  262. }
  263. /**
  264. 弹出alertController,并且有三个action按钮
  265. @param confirmOneAction 右边按钮的点击事件
  266. @param confirmTwoAction 右边按钮的点击事件
  267. @param cancleAction 取消按钮的点击事件
  268. */
  269. - (void)showAlertWithTitle:(NSString * _Nullable )title message:(NSString * _Nullable )message confirmTitleOne:(NSString * _Nullable )confirmTitleOne confirmTitleTwo:(NSString * _Nullable )confirmTitleTwo cancelTitle:(NSString * _Nullable )cancelTitle confirmOneAction:(void(^)(void))confirmOneAction confirmTwoAction:(void(^)(void))confirmTwoAction cancleAction:(void(^)(void))cancleAction {
  270. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
  271. CGFloat viewTextWideth = RQ_SCREEN_WIDTH - (20 * 2) - (40 * 2);
  272. CGFloat textHeight = [message heightForFont:[UIFont systemFontOfSize:16] width:viewTextWideth] + 16 > RQ_SCREEN_HEIGHT / 2.f? RQ_SCREEN_HEIGHT / 2.f : [message heightForFont:[UIFont systemFontOfSize:16] width:viewTextWideth] + 16;
  273. [alert removeTopCircle];
  274. alert.tintTopCircle = NO;
  275. alert.useLargerIcon = NO;
  276. alert.iconTintColor = RQ_MAIN_COLOR;
  277. alert.cornerRadius = 10;
  278. // NSString *imageName = @"提示";
  279. // CGSize imageSize = imageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 64.f));
  280. // UIImageView *iconImageView = [[UIImageView alloc] qmui_initWithSize:imageSize];
  281. // iconImageView.image = RQImageNamed(imageName);
  282. // iconImageView.contentMode = UIViewContentModeScaleAspectFill;
  283. // [alert addCustomView:iconImageView];
  284. // [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  285. // make.top.mas_offset(20);
  286. // make.centerX.mas_offset(0);
  287. // make.size.mas_equalTo(imageSize);
  288. // }];
  289. alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
  290. alert.labelTitle.font = [UIFont boldSystemFontOfSize:20];
  291. [alert.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  292. make.top.mas_offset(20);
  293. make.centerX.mas_offset(0);
  294. make.size.mas_equalTo(CGSizeMake(viewTextWideth, 21.f));
  295. }];
  296. UITextView *messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, alert.labelTitle.rq_y + alert.labelTitle.rq_height, viewTextWideth, textHeight)];
  297. messageTextView.font = RQRegularFont_13;
  298. messageTextView.editable = NO;
  299. messageTextView.textColor = RQ_MAIN_TEXT_COLOR_3;
  300. messageTextView.textAlignment = NSTextAlignmentCenter;
  301. messageTextView.text = message;
  302. [alert addCustomView:messageTextView];
  303. [messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  304. make.top.mas_equalTo(alert.labelTitle.mas_bottom).mas_offset(18);
  305. make.centerX.mas_offset(0);
  306. make.size.mas_equalTo(CGSizeMake(viewTextWideth, textHeight));
  307. }];
  308. SCLButton *confirmButton = [alert addButton:confirmTitleOne validationBlock:^BOOL{
  309. return YES;
  310. } actionBlock:confirmOneAction];
  311. confirmButton.buttonFormatBlock = ^NSDictionary* (void) {
  312. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  313. buttonConfig[@"cornerRadius"] = @"20.f";
  314. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  315. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  316. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  317. return buttonConfig;
  318. };
  319. [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
  320. make.top.mas_equalTo(messageTextView.mas_bottom).mas_offset(15);
  321. make.centerX.mas_offset(0);
  322. make.size.mas_equalTo(CGSizeMake(viewTextWideth - 16, 40.f));
  323. }];
  324. SCLButton *confirmButton1 = [alert addButton:confirmTitleTwo validationBlock:^BOOL{
  325. return YES;
  326. } actionBlock:confirmTwoAction];
  327. confirmButton1.buttonFormatBlock = ^NSDictionary* (void) {
  328. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  329. buttonConfig[@"cornerRadius"] = @"20.f";
  330. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  331. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  332. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  333. return buttonConfig;
  334. };
  335. [confirmButton1 mas_makeConstraints:^(MASConstraintMaker *make) {
  336. make.top.mas_equalTo(confirmButton.mas_bottom).mas_offset(8);
  337. make.centerX.mas_offset(0);
  338. make.size.mas_equalTo(CGSizeMake(viewTextWideth - 16, 40.f));
  339. }];
  340. SCLButton *cancelButton = [alert addButton:cancelTitle validationBlock:^BOOL{
  341. return YES;
  342. } actionBlock:cancleAction];
  343. cancelButton.buttonFormatBlock = ^NSDictionary* (void) {
  344. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  345. buttonConfig[@"cornerRadius"] = @"20.f";
  346. buttonConfig[@"backgroundColor"] = RQ_MAIN_BACKGROUNDCOLOR;
  347. buttonConfig[@"textColor"] = RQColorFromHexString(@"#D5DDE0");
  348. buttonConfig[@"borderWidth"] = @1.0f;
  349. buttonConfig[@"borderColor"] = RQColorFromHexString(@"#D5DDE0");
  350. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  351. return buttonConfig;
  352. };
  353. [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
  354. make.top.mas_equalTo(confirmButton1.mas_bottom).mas_offset(8);
  355. make.centerX.mas_offset(0);
  356. make.bottom.mas_offset(-20);
  357. make.size.mas_equalTo(CGSizeMake(viewTextWideth - 16, 40.f));
  358. }];
  359. alert.horizontalButtons = YES;
  360. alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
  361. [alert showTitle:title subTitle:nil style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
  362. }
  363. - (void)rq_ActivateVIPAlertWithComplete:(VoidBlock_Bool)complete {
  364. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
  365. @weakify(alert)
  366. [alert removeTopCircle];
  367. alert.tintTopCircle = NO;
  368. alert.useLargerIcon = NO;
  369. alert.shouldDismissOnTapOutside = YES;
  370. alert.iconTintColor = RQ_MAIN_COLOR;
  371. alert.cornerRadius = 10;
  372. alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
  373. alert.labelTitle.font = [UIFont boldSystemFontOfSize:15];
  374. UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 250, 30)];
  375. textFiled.borderStyle = UITextBorderStyleNone;
  376. textFiled.backgroundColor = RQ_LIST_BACKGROUNDCOLOR;
  377. textFiled.layer.cornerRadius = 15;
  378. textFiled.layer.borderWidth = 1;
  379. textFiled.layer.borderColor = RQ_MAIN_LINE_COLOR_1.CGColor;
  380. textFiled.clipsToBounds = YES;
  381. UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
  382. UIImageView *imageView = [[UIImageView alloc]initWithImage:RQImageNamed(@"activationIcon")];
  383. imageView.center = leftView.center;
  384. [leftView addSubview:imageView];
  385. textFiled.leftView = imageView;
  386. textFiled.leftViewMode = UITextFieldViewModeAlways; //此处用来设置leftview现实时机
  387. textFiled.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  388. textFiled.placeholder = @"请输入激活码";
  389. textFiled.tintColor = [UIColor colorWithHexString:@"#BFBFBF"];
  390. textFiled.textColor = RQ_MAIN_TEXT_COLOR_3;
  391. textFiled.font = [UIFont systemFontOfSize:13];
  392. [alert addCustomTextField:textFiled];
  393. SCLButton *closeButton = [alert addButton:@"" actionBlock:^{
  394. @strongify(alert);
  395. [alert hideView];
  396. if (complete) {
  397. complete(NO);
  398. }
  399. }];
  400. [closeButton setImage:RQImageNamed(@"close") forState:UIControlStateNormal];
  401. [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  402. make.top.mas_offset(14);
  403. make.right.mas_offset(-14);
  404. make.size.mas_equalTo(CGSizeMake(16.f, 16.f));
  405. }];
  406. SCLButton *activateBtn = [alert addButton:@"立即开通" validationBlock:^BOOL{
  407. if (textFiled.text.length <= 0) {
  408. [MBProgressHUD rq_showTips:@"请输入激活码"];
  409. }
  410. return textFiled.text.length > 0;
  411. } actionBlock:^{
  412. if (complete) {
  413. complete(YES);
  414. }
  415. }];
  416. activateBtn.buttonFormatBlock = ^NSDictionary* (void) {
  417. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  418. buttonConfig[@"cornerRadius"] = @"15.f";
  419. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  420. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  421. buttonConfig[@"font"] = [UIFont systemFontOfSize:13];
  422. return buttonConfig;
  423. };
  424. [activateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  425. make.centerX.mas_offset(0);
  426. make.bottom.mas_offset(-20);
  427. make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(100.f), 30.f));
  428. }];
  429. alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
  430. [alert showTitle:@"提示" subTitle:@"您还未开通系统,请输入激活码开通!" style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
  431. }
  432. @end