RQAlertViewManager.m 21 KB

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