RQAlertViewManager.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. //
  2. // RQAlertViewManager.m
  3. // YJZS
  4. //
  5. // Created by 张嵘 on 2022/4/11.
  6. //
  7. #import "RQAlertViewManager.h"
  8. static RQAlertViewManager *manger = nil;
  9. static dispatch_once_t onceToken;
  10. @interface RQAlertViewManager ()
  11. @property (nonatomic, readwrite, strong) UIView *commonHeaderView;
  12. @end
  13. @implementation RQAlertViewManager
  14. #pragma mark - SystemMethod
  15. + (RQAlertViewManager *)sharedManager {
  16. dispatch_once(&onceToken, ^{
  17. manger = [[self alloc] init];
  18. });
  19. return manger;
  20. }
  21. - (instancetype)init {
  22. self = [super init];
  23. if (self) {
  24. }
  25. return self;
  26. }
  27. - (void)dealloc {
  28. [[NSNotificationCenter defaultCenter] removeObserver:self];
  29. }
  30. #pragma mark - PublicMethods
  31. /**
  32. 弹出alertController,并且有两个个action按钮,分别有处理事件
  33. @param alertType 弹窗类型
  34. @param title title
  35. @param message Message
  36. @param confirmTitle 左边按钮的title
  37. @param cancelTitle 右边按钮的title
  38. @param confirmAction 左边按钮的点击事件
  39. */
  40. - (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 {
  41. [self showAlertWithAlertType:alertType title:title message:message confirmTitle:confirmTitle cancelTitle:cancelTitle confirmAction:confirmAction cancelAction:nil];
  42. }
  43. /**
  44. 弹出alertController,并且有两个个action按钮,分别有处理事件
  45. @param alertType 弹窗类型
  46. @param title title
  47. @param message Message
  48. @param confirmTitle 左边按钮的title
  49. @param cancelTitle 右边按钮的title
  50. @param confirmAction 左边按钮的点击事件
  51. @param cancelAction 右按钮的点击事件
  52. */
  53. - (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 {
  54. QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
  55. dialogViewController.headerSeparatorColor = nil;
  56. dialogViewController.headerViewBackgroundColor = UIColor.whiteColor;
  57. 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;
  58. dialogViewController.headerViewHeight = (alertType == RQAlertType_Default)? (24.f + 22.f + 16.f + textHeight + 16.f) : 180.f;
  59. NSString *headerImageName = @"";
  60. CGSize headerImageSize = CGSizeZero;
  61. switch (alertType) {
  62. case RQAlertType_Rignt:
  63. headerImageName = @"正确";
  64. headerImageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 71.f));
  65. break;
  66. case RQAlertType_Warn:
  67. headerImageName = @"提示";
  68. headerImageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 64.f));
  69. break;
  70. case RQAlertType_Error:
  71. headerImageName = @"错误";
  72. headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (277.f / 117.f));
  73. break;
  74. default:
  75. break;
  76. }
  77. UIImageView *headerIconImageView = [[UIImageView alloc] initWithImage:RQImageNamed(headerImageName)];
  78. headerIconImageView.contentMode = UIViewContentModeScaleAspectFill;
  79. if (RQStringIsNotEmpty(headerImageName)) {
  80. [dialogViewController.headerView addSubview:headerIconImageView];
  81. [headerIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.top.mas_offset((alertType == RQAlertType_Error)? 0 : 40);
  83. make.centerX.mas_offset(0);
  84. make.size.mas_equalTo(headerImageSize);
  85. }];
  86. }
  87. QMUILabel *titleLabel = [[QMUILabel alloc] qmui_initWithFont:RQSemiboldFont(20) textColor:[UIColor qmui_colorWithHexString:@"#040B26"]];
  88. titleLabel.text = title;
  89. titleLabel.textAlignment = NSTextAlignmentCenter;
  90. [dialogViewController.headerView addSubview:titleLabel];
  91. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.mas_equalTo(RQStringIsNotEmpty(headerImageName)? headerIconImageView.mas_bottom : dialogViewController.headerView.mas_top).mas_offset(24);
  93. make.centerX.mas_offset(0);
  94. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f, 22.f));
  95. }];
  96. QMUILabel *messageLabel = [[QMUILabel alloc] qmui_initWithFont:RQRegularFont_16 textColor:[UIColor qmui_colorWithHexString:@"#5C6066"]];
  97. NSMutableAttributedString *mutAttrStr = [[NSMutableAttributedString alloc] initWithString:message];
  98. if ([message containsString:@"永久删除"]) {
  99. [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"永久删除"]];
  100. }
  101. if ([message containsString:@"VIP用户的VIP权益也将失效"]) {
  102. [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"VIP用户的VIP权益也将失效"]];
  103. }
  104. if (alertType == RQAlertType_SignOut) {
  105. messageLabel.attributedText = mutAttrStr;
  106. } else {
  107. messageLabel.text = message;
  108. }
  109. messageLabel.textAlignment = NSTextAlignmentLeft;
  110. messageLabel.numberOfLines = 0;
  111. [dialogViewController.headerView addSubview:messageLabel];
  112. [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(16);
  114. make.centerX.mas_offset(0);
  115. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f - 32.f, textHeight));
  116. }];
  117. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - 80.f, 36)];
  118. contentView.backgroundColor = UIColorWhite;
  119. dialogViewController.contentView = contentView;
  120. dialogViewController.footerSeparatorColor = nil;
  121. dialogViewController.footerViewBackgroundColor = UIColor.whiteColor;
  122. dialogViewController.footerViewHeight = 84.f;
  123. dialogViewController.footerView.hidden = NO;
  124. CGFloat btnWidth = (RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16) / 2.f;
  125. QMUIButton *cancleBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  126. [cancleBtn setTitle:cancelTitle textColor:[UIColor qmui_colorWithHexString:@"#5C6066"] Font:15 fotState:UIControlStateNormal];
  127. cancleBtn.layer.borderColor = [UIColor qmui_colorWithHexString:@"#5C6066"].CGColor;
  128. cancleBtn.layer.borderWidth = 1;
  129. cancleBtn.layer.cornerRadius = 20;
  130. cancleBtn.layer.masksToBounds = YES;
  131. [cancleBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  132. [dialogViewController hide];
  133. if (cancelAction) {
  134. cancelAction(dialogViewController);
  135. }
  136. }];
  137. [dialogViewController.footerView addSubview:cancleBtn];
  138. [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  139. make.top.mas_offset(0);
  140. make.left.mas_offset(16);
  141. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  142. }];
  143. QMUIButton *confirmBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  144. [confirmBtn setTitle:confirmTitle textColor:UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
  145. [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_COLOR size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
  146. [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:[UIColor qmui_colorWithHexString:@"#8A9099"] size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateDisabled];
  147. confirmBtn.layer.cornerRadius = 20;
  148. confirmBtn.layer.masksToBounds = YES;
  149. [confirmBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  150. [dialogViewController hide];
  151. if (confirmAction) {
  152. confirmAction(dialogViewController);
  153. }
  154. }];
  155. [dialogViewController.footerView addSubview:confirmBtn];
  156. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  157. make.top.mas_offset(0);
  158. make.right.mas_offset(-16);
  159. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  160. }];
  161. if (alertType == RQAlertType_SignOut) {
  162. [confirmBtn setEnabled:!(alertType == RQAlertType_SignOut)];
  163. __block NSInteger customIndex = 11;
  164. [[[RACSignal interval:1 onScheduler:[RACScheduler mainThreadScheduler]] take:customIndex] subscribeNext:^(id x) {
  165. customIndex --;
  166. [confirmBtn setTitleNormal:[NSString stringWithFormat:@"%@(%lds)",confirmTitle,customIndex]];
  167. [confirmBtn setEnabled:customIndex <= 0];
  168. if (customIndex <= 0) {
  169. [confirmBtn setTitleNormal:confirmTitle];
  170. }
  171. }];
  172. }
  173. [dialogViewController show];
  174. }
  175. /**
  176. 弹出alertController,并且有三个action按钮
  177. @param confirmOneAction 右边按钮的点击事件
  178. @param confirmTwoAction 右边按钮的点击事件
  179. */
  180. - (void)showAlertWithConfirmOneAction:(void(^)(void))confirmOneAction confirmTwoAction:(void(^)(void))confirmTwoAction {
  181. NSString *title = @"温馨提示";
  182. NSString *message = @"请选择培训科目";
  183. NSString *cancelTitle = @"取消";
  184. NSString *confirmTitleOne = @"科目二";
  185. NSString *confirmTitleTwo = @"科目三";
  186. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindowWidth:RQ_SCREEN_WIDTH - 80.f];
  187. CGFloat viewTextWideth = RQ_SCREEN_WIDTH - (20 * 2) - (40 * 2);
  188. 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;
  189. [alert removeTopCircle];
  190. alert.tintTopCircle = NO;
  191. alert.useLargerIcon = NO;
  192. alert.iconTintColor = RQ_MAIN_COLOR;
  193. alert.cornerRadius = 10;
  194. NSString *imageName = @"提示";
  195. CGSize imageSize = imageSize = CGSizeMake((RQ_SCREEN_WIDTH - 80.f) / 3.f, ((RQ_SCREEN_WIDTH - 80.f) / 3.f) / (96.f / 64.f));
  196. UIImageView *iconImageView = [[UIImageView alloc] qmui_initWithSize:imageSize];
  197. iconImageView.image = RQImageNamed(imageName);
  198. iconImageView.contentMode = UIViewContentModeScaleAspectFill;
  199. [alert addCustomView:iconImageView];
  200. [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  201. make.top.mas_offset(20);
  202. make.centerX.mas_offset(0);
  203. make.size.mas_equalTo(imageSize);
  204. }];
  205. alert.labelTitle.textColor = RQ_MAIN_TEXT_COLOR_1;
  206. alert.labelTitle.font = [UIFont boldSystemFontOfSize:20];
  207. [alert.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  208. make.top.mas_equalTo(iconImageView.mas_bottom).mas_offset(20);
  209. make.centerX.mas_offset(0);
  210. make.size.mas_equalTo(CGSizeMake(viewTextWideth, 21.f));
  211. }];
  212. UITextView *messageTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, alert.labelTitle.rq_y + alert.labelTitle.rq_height, viewTextWideth, textHeight)];
  213. messageTextView.font = RQRegularFont_13;
  214. messageTextView.editable = NO;
  215. messageTextView.textColor = RQ_MAIN_TEXT_COLOR_3;
  216. messageTextView.textAlignment = NSTextAlignmentCenter;
  217. messageTextView.text = message;
  218. [alert addCustomView:messageTextView];
  219. [messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
  220. make.top.mas_equalTo(alert.labelTitle.mas_bottom).mas_offset(18);
  221. make.centerX.mas_offset(0);
  222. make.size.mas_equalTo(CGSizeMake(viewTextWideth, textHeight));
  223. }];
  224. SCLButton *confirmButton = [alert addButton:confirmTitleOne validationBlock:^BOOL{
  225. return YES;
  226. } actionBlock:confirmOneAction];
  227. confirmButton.buttonFormatBlock = ^NSDictionary* (void) {
  228. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  229. buttonConfig[@"cornerRadius"] = @"20.f";
  230. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  231. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  232. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  233. return buttonConfig;
  234. };
  235. [confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
  236. make.top.mas_equalTo(messageTextView.mas_bottom).mas_offset(15);
  237. make.centerX.mas_offset(0);
  238. make.size.mas_equalTo(CGSizeMake(viewTextWideth - 16, 40.f));
  239. }];
  240. SCLButton *confirmButton1 = [alert addButton:confirmTitleTwo validationBlock:^BOOL{
  241. return YES;
  242. } actionBlock:confirmTwoAction];
  243. confirmButton1.buttonFormatBlock = ^NSDictionary* (void) {
  244. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  245. buttonConfig[@"cornerRadius"] = @"20.f";
  246. buttonConfig[@"backgroundColor"] = RQ_MAIN_COLOR;
  247. buttonConfig[@"textColor"] = RQ_MAIN_TEXT_COLOR_WHITE;
  248. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  249. return buttonConfig;
  250. };
  251. [confirmButton1 mas_makeConstraints:^(MASConstraintMaker *make) {
  252. make.top.mas_equalTo(confirmButton.mas_bottom).mas_offset(8);
  253. make.centerX.mas_offset(0);
  254. make.size.mas_equalTo(CGSizeMake(viewTextWideth - 16, 40.f));
  255. }];
  256. SCLButton *cancelButton = [alert addButton:cancelTitle validationBlock:^BOOL{
  257. return YES;
  258. } actionBlock:nil];
  259. cancelButton.buttonFormatBlock = ^NSDictionary* (void) {
  260. NSMutableDictionary *buttonConfig = [[NSMutableDictionary alloc] init];
  261. buttonConfig[@"cornerRadius"] = @"20.f";
  262. buttonConfig[@"backgroundColor"] = RQ_MAIN_BACKGROUNDCOLOR;
  263. buttonConfig[@"textColor"] = RQColorFromHexString(@"#D5DDE0");
  264. buttonConfig[@"borderWidth"] = @1.0f;
  265. buttonConfig[@"borderColor"] = RQColorFromHexString(@"#D5DDE0");
  266. buttonConfig[@"font"] = [UIFont systemFontOfSize:16];
  267. return buttonConfig;
  268. };
  269. [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
  270. make.top.mas_equalTo(confirmButton1.mas_bottom).mas_offset(8);
  271. make.centerX.mas_offset(0);
  272. make.bottom.mas_offset(-20);
  273. make.size.mas_equalTo(CGSizeMake(viewTextWideth - 16, 40.f));
  274. }];
  275. alert.horizontalButtons = YES;
  276. alert.showAnimationType = SCLAlertViewShowAnimationFadeIn;
  277. [alert showTitle:title subTitle:nil style:SCLAlertViewStyleCustom closeButtonTitle:nil duration:0.f];
  278. }
  279. - (void)showEmailAlertConfirmAction:(void (^__nullable)(__kindof QMUIDialogViewController *dialogViewController, __kindof QMUITextField *textFiled))confirmAction {
  280. QMUIDialogViewController *dialogViewController = [[QMUIDialogViewController alloc] init];
  281. dialogViewController.headerSeparatorColor = nil;
  282. dialogViewController.headerViewBackgroundColor = UIColor.whiteColor;
  283. NSString *title = @"请输入您的邮箱";
  284. NSString *message = @"5分钟内将发送到您的邮箱,请注意查收。";
  285. 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;
  286. NSString *headerImageName = @"信纸边缘";
  287. CGSize headerImageSize = CGSizeMake(RQ_SCREEN_WIDTH - 80.f, (RQ_SCREEN_WIDTH - 80.f) / (290.f / 9.f));
  288. dialogViewController.headerViewHeight = headerImageSize.height + 24.f + 22.f + 16.f + textHeight + 16.f ;
  289. UIImageView *headerIconImageView = [[UIImageView alloc] initWithImage:RQImageNamed(headerImageName)];
  290. headerIconImageView.contentMode = UIViewContentModeScaleAspectFill;
  291. if (RQStringIsNotEmpty(headerImageName)) {
  292. [dialogViewController.headerView addSubview:headerIconImageView];
  293. [headerIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  294. make.top.mas_offset(0);
  295. make.centerX.mas_offset(0);
  296. make.size.mas_equalTo(headerImageSize);
  297. }];
  298. }
  299. QMUIButton *cancleBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  300. [cancleBtn setImage:RQImageNamed(@"close") forState:UIControlStateNormal];
  301. [cancleBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  302. [dialogViewController hide];
  303. }];
  304. [dialogViewController.headerView addSubview:cancleBtn];
  305. [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  306. make.top.mas_equalTo(headerIconImageView.mas_bottom).mas_offset(16);
  307. make.right.mas_offset(-16);
  308. make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(16.f), RQ_FIT_HORIZONTAL(16.f)));
  309. }];
  310. QMUILabel *titleLabel = [[QMUILabel alloc] qmui_initWithFont:RQSemiboldFont(20) textColor:[UIColor qmui_colorWithHexString:@"#040B26"]];
  311. titleLabel.text = title;
  312. titleLabel.textAlignment = NSTextAlignmentCenter;
  313. [dialogViewController.headerView addSubview:titleLabel];
  314. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  315. make.top.mas_equalTo(RQStringIsNotEmpty(headerImageName)? headerIconImageView.mas_bottom : dialogViewController.headerView.mas_top).mas_offset(24);
  316. make.left.mas_offset(16);
  317. make.right.mas_equalTo(cancleBtn.mas_left).mas_offset(-8);
  318. make.height.mas_equalTo(22.f);
  319. }];
  320. QMUILabel *messageLabel = [[QMUILabel alloc] qmui_initWithFont:RQRegularFont_16 textColor:[UIColor qmui_colorWithHexString:@"#5C6066"]];
  321. NSMutableAttributedString *mutAttrStr = [[NSMutableAttributedString alloc] initWithString:message];
  322. if ([message containsString:@"永久删除"]) {
  323. [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"永久删除"]];
  324. }
  325. if ([message containsString:@"VIP用户的VIP权益也将失效"]) {
  326. [mutAttrStr addAttribute:NSForegroundColorAttributeName value:RQ_MAIN_TEXT_COLOR_RED range:[message rangeOfString:@"VIP用户的VIP权益也将失效"]];
  327. }
  328. messageLabel.text = message;
  329. messageLabel.textAlignment = NSTextAlignmentCenter;
  330. messageLabel.numberOfLines = 0;
  331. [dialogViewController.headerView addSubview:messageLabel];
  332. [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  333. make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(16);
  334. make.centerX.mas_offset(0);
  335. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f - 32.f, textHeight));
  336. }];
  337. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - 80.f, 68)];
  338. contentView.backgroundColor = UIColorWhite;
  339. UIView *bgView = [[UIView alloc] init];
  340. bgView.backgroundColor = RQColorFromHexString(@"#F2F3F5");
  341. bgView.layer.cornerRadius = 18.f;
  342. bgView.layer.borderWidth = 1;
  343. bgView.layer.borderColor = RQColorAlpha(124, 129, 136, 0.16).CGColor;
  344. bgView.layer.masksToBounds = YES;
  345. [contentView addSubview:bgView];
  346. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  347. make.left.top.mas_offset(16);
  348. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH - 80.f - 32.f, 36));
  349. }];
  350. UIImageView *iconImageView = [[UIImageView alloc] initWithImage:RQImageNamed(@"邮箱")];
  351. [bgView addSubview:iconImageView];
  352. [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  353. make.left.mas_offset(16);
  354. make.centerY.mas_offset(0);
  355. make.size.mas_equalTo(CGSizeMake(RQ_FIT_HORIZONTAL(14.4f), RQ_FIT_HORIZONTAL(10.9f)));
  356. }];
  357. QMUITextField *textFiled = [[QMUITextField alloc] init];
  358. textFiled.frame = CGRectMake(CGRectGetMaxX(iconImageView.frame) + 16.f, 0, RQ_SCREEN_WIDTH - 80.f - 32.f - CGRectGetMaxX(iconImageView.frame) - 24.f, 36);
  359. textFiled.placeholder = @"请输入您的邮箱";
  360. textFiled.placeholderColor = RQColorFromHexString(@"#BFBFBF");
  361. textFiled.keyboardType = UIKeyboardTypeEmailAddress;
  362. textFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
  363. textFiled.text = RQStringIsNotEmpty(RQ_COMMON_MANAGER.historyEmailStr)? RQ_COMMON_MANAGER.historyEmailStr : @"";
  364. [bgView addSubview:textFiled];
  365. [textFiled mas_makeConstraints:^(MASConstraintMaker *make) {
  366. make.left.mas_equalTo(iconImageView.mas_right).mas_offset(8);
  367. make.top.bottom.mas_offset(0);
  368. make.right.mas_offset(-16);
  369. }];
  370. dialogViewController.contentView = contentView;
  371. dialogViewController.footerSeparatorColor = nil;
  372. dialogViewController.footerViewBackgroundColor = UIColor.whiteColor;
  373. dialogViewController.footerViewHeight = 84.f;
  374. dialogViewController.footerView.hidden = NO;
  375. CGFloat btnWidth = (RQ_SCREEN_WIDTH - 80.f - (16 * 2) - 16) / 2.f;
  376. QMUIButton *confirmBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  377. [confirmBtn setTitle:@"确认" textColor:UIColor.whiteColor Font:15 fotState:UIControlStateNormal];
  378. [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:RQ_MAIN_COLOR size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateNormal];
  379. [confirmBtn setBackgroundImage:[UIImage qmui_imageWithColor:[UIColor qmui_colorWithHexString:@"#8A9099"] size:CGSizeMake(100.f, 40.f) cornerRadius:0] forState:UIControlStateDisabled];
  380. confirmBtn.layer.cornerRadius = 20;
  381. confirmBtn.layer.masksToBounds = YES;
  382. [confirmBtn setBlockForControlEvents:UIControlEventTouchUpInside block:^(id _Nonnull sender) {
  383. if ([NSString rq_isValidEmail:textFiled.text]) {
  384. RQ_COMMON_MANAGER.historyEmailStr = textFiled.text;
  385. [dialogViewController hide];
  386. if (confirmAction) {
  387. confirmAction(dialogViewController, textFiled);
  388. }
  389. } else {
  390. [MBProgressHUD rq_showTips:@"请输入正确的邮箱" addedToView:dialogViewController.view];
  391. }
  392. }];
  393. [dialogViewController.footerView addSubview:confirmBtn];
  394. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  395. make.center.mas_offset(0);
  396. make.size.mas_equalTo(CGSizeMake(btnWidth, 40.f));
  397. }];
  398. [dialogViewController show];
  399. }
  400. - (UIView *)commonHeaderView {
  401. if (!_commonHeaderView) {
  402. _commonHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH - (40 * 2), 117)];
  403. }
  404. return _commonHeaderView;
  405. }
  406. @end