WMZAlert.m 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. //
  2. // WMZAlert.m
  3. // WMZAlert
  4. //
  5. // Created by wmz on 2018/10/9.
  6. // Copyright © 2018年 wmz. All rights reserved.
  7. //
  8. #import "WMZAlert.h"
  9. #define title_Font 16.0f
  10. #define text_Font 13.0f
  11. #define kDevice_Height [UIScreen mainScreen].bounds.size.height
  12. #define kDevice_Width [UIScreen mainScreen].bounds.size.width
  13. #define NavigationBar_Height (([[UIApplication sharedApplication] statusBarFrame].size.height) + 44)
  14. #define wmz_GetWNum(A) (A)/2.0*(kDevice_Width/375)
  15. #define wmz_GetHNum(B) (B)/2.0*(kDevice_Height/667)
  16. #define HEX_COLOR(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  17. @interface WMZAlert()<UITextFieldDelegate,UITextViewDelegate,UITableViewDelegate,UITableViewDataSource>
  18. {
  19. dispatch_source_t timer; //定时器
  20. }
  21. @property (nonatomic, copy) NavClickBlock leftButtonClickHandle; //取消按钮回调
  22. @property (nonatomic, assign) AlertType type; //弹窗类型
  23. @property (nonatomic, copy) NavClickBlock rightButtonClickHandle; //确定按钮回调
  24. @property (nonatomic, strong) UIView *mainView; //支付视图
  25. @property (nonatomic, strong) UILabel *titleLabel; //标题视图
  26. @property (nonatomic, strong) UIView *passView; //密码框视图
  27. @property (nonatomic, strong) UITextField *payField; //密码编辑框(不可见)
  28. @property (nonatomic, strong) UITextView *alertTextView; //文本写入框
  29. @property (nonatomic, strong) UILabel *mainText; //主要文本
  30. @property (nonatomic, strong) NSString *placeHolderText; //提示语内容
  31. @property (nonatomic, strong) UIViewController *nowVC; //当前VC
  32. @property (nonatomic, strong) UITableView *tableView; //tableView
  33. @property (nonatomic, strong) NSArray *dataArr; //选择器数据源
  34. @property (nonatomic, strong) id selectID; //选中的
  35. @property (nonatomic, assign) CGFloat mainWidth; //背景宽度
  36. @property (nonatomic, strong) UIButton *cancelBtn; //取消按钮
  37. @property (nonatomic, strong) UIButton *okBtn; //确定按钮
  38. @property (nonatomic, strong) UIButton *closeBtn; //关闭按钮
  39. @property (nonatomic, strong) UIView *leftLine; //中间线
  40. @property (nonatomic, strong) UIScrollView *shareView; //分享
  41. @property (nonatomic, strong) NSDictionary *shareDic; //分享数据源
  42. @end
  43. @implementation WMZAlert
  44. //初始化
  45. + (instancetype)shareInstance{
  46. return [[self alloc]init];
  47. }
  48. //简单化弹窗没有回调
  49. - (void)showAlertWithType:(AlertType)type
  50. textTitle:(id) text{
  51. [self showAlertWithType:type sueprVC:nil leftTitle:nil rightTitle:nil headTitle:nil textTitle:text headTitleColor:nil textTitleColor:nil backColor:nil okBtnColor:nil cancelBtnColor:nil leftHandle:nil rightHandle:nil];
  52. }
  53. //简单化弹窗带回调
  54. - (void)showAlertWithType:(AlertType)type
  55. headTitle:(NSString*)title
  56. textTitle:(id) text
  57. leftHandle:(NavClickBlock)leftBlock
  58. rightHandle:(NavClickBlock)rightBlock{
  59. [self showAlertWithType:type sueprVC:nil leftTitle:nil rightTitle:nil headTitle:title textTitle:text headTitleColor:nil textTitleColor:nil backColor:nil okBtnColor:nil cancelBtnColor:nil leftHandle:leftBlock rightHandle:rightBlock];
  60. }
  61. //最全面弹窗可以设置按钮颜色等
  62. - (void)showAlertWithType:(AlertType)type
  63. sueprVC:(UIViewController*)VC
  64. leftTitle:(NSString*)leftText
  65. rightTitle:(NSString*)rightText
  66. headTitle:(NSString*)title
  67. textTitle:(id) text
  68. headTitleColor:(UIColor*)titleColor
  69. textTitleColor:(UIColor*)textColor
  70. backColor:(UIColor*)backColor
  71. okBtnColor:(UIColor*)okColor
  72. cancelBtnColor:(UIColor*)cancelColor
  73. leftHandle:(NavClickBlock)leftBlock
  74. rightHandle:(NavClickBlock)rightBlock{
  75. self.view.backgroundColor = [UIColor clearColor];
  76. if (!VC) {
  77. VC = [WMZAlert getCurrentVC];
  78. }
  79. self.nowVC = VC;
  80. id addView = [self appearViewWithType:type sueprVC:VC leftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor leftHandle:leftBlock rightHandle:rightBlock];
  81. if (!addView) {
  82. return;
  83. }
  84. if ([addView isKindOfClass:[UIView class]]) {
  85. [self.view addSubview:addView];
  86. self.modalPresentationStyle = UIModalPresentationOverFullScreen;
  87. self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  88. [VC presentViewController:self animated:YES completion:nil];
  89. if (type == AlertTypeAuto|| type == AlertTypeToast) {
  90. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  91. [self closeView];
  92. });
  93. }
  94. }else{
  95. [VC presentViewController:addView animated:YES completion:nil];
  96. }
  97. }
  98. //添加阴影
  99. - (void)addShadow{
  100. UIView *shadowView = [[UIView alloc] initWithFrame:self.view.bounds];
  101. shadowView.backgroundColor = [UIColor blackColor];
  102. [self.view addSubview:shadowView];
  103. shadowView.alpha = 0.4f;
  104. }
  105. //根据type添加不同的视图
  106. - (id)appearViewWithType:(AlertType)type
  107. sueprVC:(UIViewController*)VC
  108. leftTitle:(NSString*)leftText
  109. rightTitle:(NSString*)rightText
  110. headTitle:(NSString*)title
  111. textTitle:(id) text
  112. headTitleColor:(UIColor*)titleColor
  113. textTitleColor:(UIColor*)textColor
  114. backColor:(UIColor*)backColor
  115. okBtnColor:(UIColor*)okColor
  116. cancelBtnColor:(UIColor*)cancelColor
  117. leftHandle:(NavClickBlock)leftBlock
  118. rightHandle:(NavClickBlock)rightBlock{
  119. self.leftButtonClickHandle = leftBlock;
  120. self.rightButtonClickHandle = rightBlock;
  121. self.type = type;
  122. switch (type) {
  123. case AlertTypeNornal: //默认弹窗
  124. {
  125. return [self AlertTypeNornalViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  126. }
  127. break;
  128. case AlertTypeSystemPush: //系统默认弹窗
  129. {
  130. return [self AlertTypeSystemPushViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  131. }
  132. break;
  133. case AlertTypeSystemSheet: //系统底部弹窗
  134. {
  135. return [self AlertTypeSystemSheetViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  136. }
  137. break;
  138. case AlertTypeAuto:{ //默认自动消失弹窗
  139. return [self AlertTypeAutoViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  140. }
  141. break;
  142. case AlertTypePay:{ //支付弹窗
  143. return [self AlertTypemainViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  144. }
  145. break;
  146. case AlertTypeToast:{ //吐丝弹窗显示在上部
  147. return [self AlertTypeToastViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  148. }
  149. break;
  150. case AlertTypeWrite:{ //可输入内容的弹窗
  151. return [self AlertTypeWriteViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  152. }
  153. break;
  154. case AlertTypeTime:{ //倒计时弹窗
  155. return [self AlertTypeTimeViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  156. }
  157. break;
  158. case AlertTypeSelect:{ //选择器弹窗
  159. return [self AlertTypeSelectViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  160. }
  161. break;
  162. case AlertTypeShare:{ //分享弹窗
  163. return [self AlertTypeShareViewWithLeftTitle:leftText rightTitle:rightText headTitle:title textTitle:text headTitleColor:titleColor textTitleColor:textColor backColor:backColor okBtnColor:okColor cancelBtnColor:cancelColor];
  164. }
  165. break;
  166. default:
  167. break;
  168. }
  169. return [UIView new];
  170. }
  171. //默认弹窗
  172. - (id)AlertTypeNornalViewWithLeftTitle:(NSString*)leftText
  173. rightTitle:(NSString*)rightText
  174. headTitle:(NSString*)title
  175. textTitle:(id) text
  176. headTitleColor:(UIColor*)titleColor
  177. textTitleColor:(UIColor*)textColor
  178. backColor:(UIColor*)backColor
  179. okBtnColor:(UIColor*)okColor
  180. cancelBtnColor:(UIColor*)cancelColor{
  181. [self addShadow];
  182. [self setMainViewWithColor:backColor withFrame:CGRectMake(0, 0, wmz_GetWNum(480), wmz_GetHNum(267)) withRadius:8.0f];
  183. [self setTitleLabelWithTitle:title?:@"提示" WithTextColor:titleColor?:[UIColor blackColor] WithNum:5 withFrame:CGRectMake(0, wmz_GetHNum(39), self.mainWidth-wmz_GetWNum(30), wmz_GetHNum(31)) isCenter:YES];
  184. [self setMaintextWithText:text WithTextColor:textColor WithNum:25 withFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame)+wmz_GetHNum(39), self.mainWidth-wmz_GetWNum(40), wmz_GetHNum(23)) isCenter:YES withFont:[UIFont systemFontOfSize:text_Font]];
  185. UIView *line = [self getLineViewWithColor:HEX_COLOR(0x999999) withFrame:CGRectMake(0, CGRectGetMaxY(self.mainText.frame)+wmz_GetHNum(56), self.mainWidth, 0.5f) withAlpha:0.5f];
  186. [self.mainView addSubview:line];
  187. if (self.leftButtonClickHandle) {
  188. [self setCancelBtnWithTextColor:cancelColor withTitle:leftText withFrame:CGRectMake(0, CGRectGetMaxY(line.frame), self.mainWidth/2-0.25, wmz_GetHNum(88))];
  189. [self.mainView addSubview:self.leftLine];
  190. }
  191. [self setOkBtnWithTextColor:okColor withTitle:rightText withFrame:CGRectMake(self.leftButtonClickHandle?CGRectGetMaxX(self.leftLine.frame):0, CGRectGetMaxY(line.frame), self.leftButtonClickHandle?self.mainWidth/2-0.25f:self.mainWidth, wmz_GetHNum(88))];
  192. [self reSetMainViewFrame:CGRectMake(0, 0, wmz_GetWNum(480), CGRectGetMaxY(self.okBtn.frame))];
  193. return self.mainView;
  194. }
  195. //系统默认弹窗
  196. - (id)AlertTypeSystemPushViewWithLeftTitle:(NSString*)leftText
  197. rightTitle:(NSString*)rightText
  198. headTitle:(NSString*)title
  199. textTitle:(id) text
  200. headTitleColor:(UIColor*)titleColor
  201. textTitleColor:(UIColor*)textColor
  202. backColor:(UIColor*)backColor
  203. okBtnColor:(UIColor*)okColor
  204. cancelBtnColor:(UIColor*)cancelColor{
  205. UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:text preferredStyle:UIAlertControllerStyleAlert];
  206. __block WMZAlert *weakSelf = self;
  207. if (self.leftButtonClickHandle) {
  208. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:leftText?:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  209. if (weakSelf.leftButtonClickHandle) {
  210. weakSelf.leftButtonClickHandle(nil);
  211. }
  212. }];
  213. [alert addAction:cancelAction];
  214. }
  215. UIAlertAction *okAction = [UIAlertAction actionWithTitle:rightText?:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  216. if (weakSelf.rightButtonClickHandle) {
  217. weakSelf.rightButtonClickHandle(nil);
  218. }
  219. }];
  220. [alert addAction:okAction];
  221. return alert;
  222. }
  223. //系统底部弹窗
  224. - (id)AlertTypeSystemSheetViewWithLeftTitle:(NSString*)leftText
  225. rightTitle:(NSString*)rightText
  226. headTitle:(NSString*)title
  227. textTitle:(id) text
  228. headTitleColor:(UIColor*)titleColor
  229. textTitleColor:(UIColor*)textColor
  230. backColor:(UIColor*)backColor
  231. okBtnColor:(UIColor*)okColor
  232. cancelBtnColor:(UIColor*)cancelColor{
  233. UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:text preferredStyle:UIAlertControllerStyleActionSheet];
  234. __block WMZAlert *weakSelf = self;
  235. if (self.leftButtonClickHandle) {
  236. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:leftText?:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  237. if (weakSelf.leftButtonClickHandle) {
  238. weakSelf.leftButtonClickHandle(nil);
  239. }
  240. }];
  241. [alert addAction:cancelAction];
  242. }
  243. UIAlertAction *okAction = [UIAlertAction actionWithTitle:rightText?:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  244. if (weakSelf.rightButtonClickHandle) {
  245. weakSelf.rightButtonClickHandle(nil);
  246. }
  247. }];
  248. [alert addAction:okAction];
  249. return alert;
  250. }
  251. //默认自动消失弹窗
  252. - (id)AlertTypeAutoViewWithLeftTitle:(NSString*)leftText
  253. rightTitle:(NSString*)rightText
  254. headTitle:(NSString*)title
  255. textTitle:(id) text
  256. headTitleColor:(UIColor*)titleColor
  257. textTitleColor:(UIColor*)textColor
  258. backColor:(UIColor*)backColor
  259. okBtnColor:(UIColor*)okColor
  260. cancelBtnColor:(UIColor*)cancelColor{
  261. [self addShadow];
  262. [self setMainViewWithColor:backColor withFrame:CGRectMake(0, 0, wmz_GetWNum(480), wmz_GetHNum(267)) withRadius:8.0f];
  263. [self setMaintextWithText:text WithTextColor:textColor WithNum:30 withFrame:CGRectMake(0, wmz_GetHNum(30), self.mainWidth-wmz_GetWNum(40), wmz_GetHNum(23)) isCenter:YES withFont:[UIFont systemFontOfSize:text_Font]];
  264. [self reSetMainViewFrame:CGRectMake(0, 0, wmz_GetWNum(480), CGRectGetMaxY(self.mainText.frame)+wmz_GetHNum(30))];
  265. return self.mainView;
  266. }
  267. //支付弹窗
  268. - (id)AlertTypemainViewWithLeftTitle:(NSString*)leftText
  269. rightTitle:(NSString*)rightText
  270. headTitle:(NSString*)title
  271. textTitle:(id) text
  272. headTitleColor:(UIColor*)titleColor
  273. textTitleColor:(UIColor*)textColor
  274. backColor:(UIColor*)backColor
  275. okBtnColor:(UIColor*)okColor
  276. cancelBtnColor:(UIColor*)cancelColor{
  277. //监听键盘出现
  278. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  279. [self addShadow];
  280. [self setMainViewWithColor:backColor withFrame:CGRectMake(0, 0, wmz_GetWNum(480), wmz_GetHNum(267)) withRadius:8.0f];
  281. self.closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  282. [self.closeBtn addTarget:self action:@selector(closeAction:) forControlEvents:UIControlEventTouchUpInside];
  283. [self.closeBtn setTitle:rightText?:@"x" forState:UIControlStateNormal];
  284. [self.closeBtn setTitleColor:okColor?:HEX_COLOR(0x999999) forState:UIControlStateNormal];
  285. self.closeBtn.backgroundColor = [UIColor whiteColor];
  286. self.closeBtn.frame = CGRectMake(wmz_GetWNum(20), wmz_GetHNum(20), wmz_GetWNum(50), wmz_GetWNum(50));
  287. [self.mainView addSubview:self.closeBtn];
  288. [self setTitleLabelWithTitle:title?:@"请输入支付密码" WithTextColor:titleColor?:[UIColor blackColor] WithNum:5 withFrame:CGRectMake(wmz_GetWNum(80), wmz_GetHNum(25), self.mainWidth-wmz_GetWNum(160), wmz_GetHNum(31)) isCenter:NO];
  289. UIView *upLine = [self getLineViewWithColor:[UIColor greenColor] withFrame:CGRectMake(wmz_GetWNum(15), CGRectGetMaxY(self.titleLabel.frame)+wmz_GetHNum(25), self.mainWidth-wmz_GetWNum(30), 0.5f) withAlpha:0.5f];
  290. [self.mainView addSubview:upLine];
  291. [self setMaintextWithText:[NSString stringWithFormat:@"¥%@.00",text] WithTextColor:textColor WithNum:1 withFrame:CGRectMake(0, CGRectGetMaxY(upLine.frame)+wmz_GetHNum(30), self.mainWidth, wmz_GetHNum(60)) isCenter:YES withFont:[UIFont fontWithName:@"Helvetica-Bold" size:20.0f]];
  292. UIView *downLine = [self getLineViewWithColor:HEX_COLOR(0x999999) withFrame:CGRectMake(wmz_GetWNum(15), CGRectGetMaxY(self.mainText.frame)+wmz_GetHNum(30), self.mainWidth-wmz_GetWNum(30), 0.5f) withAlpha:0.5f];
  293. [self.mainView addSubview:downLine];
  294. self.payField = [UITextField new];
  295. self.payField.frame = CGRectMake(wmz_GetWNum(15), CGRectGetMaxY(downLine.frame)+wmz_GetHNum(20), self.mainWidth-wmz_GetWNum(30), 0);
  296. self.payField.delegate = self;
  297. [self.mainView addSubview:self.payField];
  298. [self.mainView sendSubviewToBack:self.payField];
  299. self.payField.keyboardType = UIKeyboardTypeNumberPad;
  300. [self.payField addTarget:self action:@selector(textField1TextChange:) forControlEvents:UIControlEventEditingChanged];
  301. [self.payField becomeFirstResponder];
  302. self.passView = [UIView new];
  303. self.passView.backgroundColor = [UIColor whiteColor];
  304. self.passView.frame = CGRectMake(wmz_GetWNum(15), CGRectGetMaxY(downLine.frame)+wmz_GetHNum(20), self.mainWidth-wmz_GetWNum(30), (self.mainWidth-wmz_GetWNum(30))/6);
  305. [self.mainView addSubview:self.passView];
  306. CGFloat passViewWidth = self.passView.frame.size.width;
  307. UILabel *tempLabel = nil;
  308. for (int i = 0; i<6; i++) {
  309. UILabel *password = [UILabel new];
  310. password.layer.masksToBounds = YES;
  311. password.layer.borderColor = HEX_COLOR(0x999999).CGColor;
  312. password.tag = 100+i;
  313. password.layer.borderWidth = 0.5f;
  314. password.textColor = textColor?:[UIColor blackColor];
  315. password.textAlignment = NSTextAlignmentCenter;
  316. password.text = @"";
  317. [password setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20.0f]];
  318. if (!tempLabel) {
  319. password.frame = CGRectMake(0, 0, passViewWidth/6, self.passView.frame.size.height);
  320. }else{
  321. password.frame = CGRectMake(CGRectGetMaxX(tempLabel.frame), 0, passViewWidth/6, self.passView.frame.size.height);
  322. }
  323. tempLabel = password;
  324. [self.passView addSubview:password];
  325. }
  326. [self reSetMainViewFrame:CGRectMake(0, 0, wmz_GetWNum(480), CGRectGetMaxY(self.passView.frame)+wmz_GetHNum(20))];
  327. return self.mainView;
  328. }
  329. //吐丝弹窗显示在上部
  330. - (id)AlertTypeToastViewWithLeftTitle:(NSString*)leftText
  331. rightTitle:(NSString*)rightText
  332. headTitle:(NSString*)title
  333. textTitle:(id) text
  334. headTitleColor:(UIColor*)titleColor
  335. textTitleColor:(UIColor*)textColor
  336. backColor:(UIColor*)backColor
  337. okBtnColor:(UIColor*)okColor
  338. cancelBtnColor:(UIColor*)cancelColor{
  339. [self setMainViewWithColor:backColor?:[UIColor lightGrayColor] withFrame:CGRectMake(0, 0, kDevice_Width, wmz_GetHNum(267)) withRadius:0];
  340. //判断toust显示的y值
  341. CGRect statusRect = [[UIApplication sharedApplication] statusBarFrame];
  342. CGFloat needHight = statusRect.size.height;
  343. UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
  344. if ([rootViewController isKindOfClass:[UITabBarController class]]) {
  345. UINavigationController *na = [(UITabBarController *)rootViewController selectedViewController];
  346. if ([na visibleViewController]) {
  347. needHight = NavigationBar_Height;
  348. }
  349. }
  350. if ([rootViewController isKindOfClass:[UINavigationController class]]){
  351. needHight = NavigationBar_Height;
  352. }
  353. [self setMaintextWithText:text WithTextColor:textColor WithNum:3 withFrame:CGRectMake(wmz_GetWNum(10), wmz_GetHNum(20), self.mainWidth-wmz_GetWNum(20), wmz_GetHNum(23)) isCenter:YES withFont:[UIFont systemFontOfSize:text_Font]];
  354. self.mainView.frame = CGRectMake(0, needHight, kDevice_Width, CGRectGetMaxY(self.mainText.frame)+wmz_GetHNum(20));
  355. return self.mainView;
  356. }
  357. //可输入内容的弹窗
  358. - (id)AlertTypeWriteViewWithLeftTitle:(NSString*)leftText
  359. rightTitle:(NSString*)rightText
  360. headTitle:(NSString*)title
  361. textTitle:(id) text
  362. headTitleColor:(UIColor*)titleColor
  363. textTitleColor:(UIColor*)textColor
  364. backColor:(UIColor*)backColor
  365. okBtnColor:(UIColor*)okColor
  366. cancelBtnColor:(UIColor*)cancelColor{
  367. //监听键盘出现
  368. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  369. [self addShadow];
  370. [self setMainViewWithColor:backColor withFrame:CGRectMake(0, 0, wmz_GetWNum(560), wmz_GetHNum(267)) withRadius:10.0f];
  371. [self setTitleLabelWithTitle:title?:@"请输入内容" WithTextColor:titleColor?:[UIColor blackColor] WithNum:5 withFrame:CGRectMake(0, wmz_GetHNum(20), self.mainWidth-wmz_GetWNum(30), wmz_GetHNum(31)) isCenter:YES];
  372. self.alertTextView = [UITextView new];
  373. self.alertTextView.layer.cornerRadius = 8.0f;
  374. self.alertTextView.layer.masksToBounds = YES;
  375. self.alertTextView.backgroundColor = backColor?:HEX_COLOR(0xe0e0e0);
  376. self.alertTextView.frame = CGRectMake(wmz_GetWNum(20), CGRectGetMaxY(self.titleLabel.frame)+wmz_GetHNum(20), self.mainWidth-wmz_GetWNum(40),wmz_GetHNum(200));
  377. self.alertTextView.font = [UIFont systemFontOfSize:text_Font];
  378. self.alertTextView.textColor = textColor?:[UIColor blackColor];
  379. self.alertTextView.delegate = self;
  380. [self.alertTextView becomeFirstResponder];
  381. [self.mainView addSubview:self.alertTextView];
  382. [self setMaintextWithText:text?:@"请输入内容" WithTextColor:titleColor?:[UIColor whiteColor] WithNum:4 withFrame:CGRectMake(wmz_GetWNum(15), wmz_GetWNum(15), self.mainWidth, wmz_GetHNum(30)) isCenter:NO withFont:[UIFont systemFontOfSize:text_Font]];
  383. self.placeHolderText = self.mainText.text;
  384. UIView *line = [self getLineViewWithColor:HEX_COLOR(0x999999) withFrame:CGRectMake(0, CGRectGetMaxY(self.alertTextView.frame)+wmz_GetHNum(20), self.mainWidth, 0.5f) withAlpha:0.5f];
  385. [self.mainView addSubview:line];
  386. if (self.leftButtonClickHandle) {
  387. [self setCancelBtnWithTextColor:cancelColor withTitle:leftText withFrame:CGRectMake(0, CGRectGetMaxY(line.frame), self.mainWidth/2-0.25f, wmz_GetHNum(88))];
  388. [self.mainView addSubview:self.leftLine];
  389. }
  390. [self setOkBtnWithTextColor:okColor withTitle:rightText withFrame:CGRectMake(self.leftButtonClickHandle?CGRectGetMaxX(self.leftLine.frame):0, CGRectGetMaxY(line.frame), self.leftButtonClickHandle?self.mainWidth/2-0.25f:self.mainWidth, wmz_GetHNum(88))];
  391. [self reSetMainViewFrame:CGRectMake(0, 0, wmz_GetWNum(560), CGRectGetMaxY(self.okBtn.frame))];
  392. return self.mainView;
  393. }
  394. //倒计时弹窗
  395. - (id)AlertTypeTimeViewWithLeftTitle:(NSString*)leftText
  396. rightTitle:(NSString*)rightText
  397. headTitle:(NSString*)title
  398. textTitle:(id) text
  399. headTitleColor:(UIColor*)titleColor
  400. textTitleColor:(UIColor*)textColor
  401. backColor:(UIColor*)backColor
  402. okBtnColor:(UIColor*)okColor
  403. cancelBtnColor:(UIColor*)cancelColor{
  404. if (text) {
  405. if ([text integerValue]<=0) {
  406. return nil;
  407. }
  408. }
  409. [self addShadow];
  410. [self setMainViewWithColor:backColor withFrame:CGRectMake(0, 0, wmz_GetWNum(480), wmz_GetHNum(267)) withRadius:8.0f];
  411. [self setTitleLabelWithTitle:title?:@"倒计时" WithTextColor:titleColor?:[UIColor blackColor] WithNum:5 withFrame:CGRectMake(0, wmz_GetHNum(20), self.mainWidth-wmz_GetWNum(30), wmz_GetHNum(31)) isCenter:YES];
  412. [self setMaintextWithText:text?[WMZAlert getMMSSFromSS:text]:@"00 : 00 : 00" WithTextColor:textColor WithNum:25 withFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame)+wmz_GetHNum(39), self.mainWidth-wmz_GetWNum(40), wmz_GetHNum(23)) isCenter:YES withFont:[UIFont fontWithName:@"Helvetica-Bold" size:22.0f]];
  413. UIView *line = [self getLineViewWithColor:HEX_COLOR(0x999999) withFrame:CGRectMake(0, CGRectGetMaxY(self.mainText.frame)+wmz_GetHNum(56), self.mainWidth, 0.5f) withAlpha:0.5f];
  414. [self.mainView addSubview:line];
  415. [self setOkBtnWithTextColor:okColor withTitle:rightText withFrame:CGRectMake(0, CGRectGetMaxY(line.frame), self.mainWidth, wmz_GetHNum(88))];
  416. [self reSetMainViewFrame:CGRectMake(0, 0, wmz_GetWNum(480), CGRectGetMaxY(self.okBtn.frame))];
  417. [self createTimer:text?:@"0"];
  418. return self.mainView;
  419. }
  420. //选择器弹窗
  421. - (id)AlertTypeSelectViewWithLeftTitle:(NSString*)leftText
  422. rightTitle:(NSString*)rightText
  423. headTitle:(NSString*)title
  424. textTitle:(id) text
  425. headTitleColor:(UIColor*)titleColor
  426. textTitleColor:(UIColor*)textColor
  427. backColor:(UIColor*)backColor
  428. okBtnColor:(UIColor*)okColor
  429. cancelBtnColor:(UIColor*)cancelColor{
  430. if (![text isKindOfClass:[NSArray class]]) {
  431. NSLog(@"请输入数组");
  432. return nil;
  433. }
  434. self.dataArr = [NSArray arrayWithArray:text];
  435. [self addShadow];
  436. [self setMainViewWithColor:backColor withFrame:CGRectMake(0, 0, wmz_GetWNum(480), wmz_GetHNum(267)) withRadius:8.0f];
  437. [self setTitleLabelWithTitle:title?:@"请选择" WithTextColor:titleColor?:[UIColor blackColor] WithNum:5 withFrame:CGRectMake(0, wmz_GetHNum(20), self.mainWidth-wmz_GetWNum(30), wmz_GetHNum(31)) isCenter:YES];
  438. UIView *upLine = [self getLineViewWithColor:HEX_COLOR(0x999999) withFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame)+wmz_GetHNum(20), self.mainWidth, 0.5f) withAlpha:0.5f];
  439. [self.mainView addSubview:upLine];
  440. [self.mainView addSubview:self.tableView];
  441. self.tableView.frame = CGRectMake(0, CGRectGetMaxY(upLine.frame), self.mainWidth,self.dataArr.count>=8?8*wmz_GetHNum(70):self.dataArr.count*wmz_GetHNum(70));
  442. UIView *line = [self getLineViewWithColor:HEX_COLOR(0x999999) withFrame:CGRectMake(0, CGRectGetMaxY(self.tableView.frame), self.mainWidth, 0.5f) withAlpha:0.5f];
  443. [self.mainView addSubview:line];
  444. [self setCancelBtnWithTextColor:cancelColor withTitle:leftText withFrame:CGRectMake(0, CGRectGetMaxY(line.frame), self.mainWidth/2, wmz_GetHNum(88))];
  445. [self setOkBtnWithTextColor:okColor withTitle:rightText withFrame:CGRectMake(self.mainWidth/2, CGRectGetMaxY(line.frame), self.mainWidth/2, wmz_GetHNum(88))];
  446. [self reSetMainViewFrame:CGRectMake(0, 0, wmz_GetWNum(480), CGRectGetMaxY(self.okBtn.frame))];
  447. return self.mainView;
  448. }
  449. //分享弹窗
  450. - (id)AlertTypeShareViewWithLeftTitle:(NSString*)leftText
  451. rightTitle:(NSString*)rightText
  452. headTitle:(NSString*)title
  453. textTitle:(id) text
  454. headTitleColor:(UIColor*)titleColor
  455. textTitleColor:(UIColor*)textColor
  456. backColor:(UIColor*)backColor
  457. okBtnColor:(UIColor*)okColor
  458. cancelBtnColor:(UIColor*)cancelColor{
  459. if (![text isKindOfClass:[NSDictionary class]]) {
  460. NSLog(@"请输入字典");
  461. return nil;
  462. }
  463. self.shareDic = [NSDictionary dictionaryWithDictionary:text];
  464. [self addShadow];
  465. [self setMainViewWithColor:backColor withFrame:CGRectMake(wmz_GetWNum(30), 0, kDevice_Width-wmz_GetWNum(60), wmz_GetHNum(267)) withRadius:8.0f];
  466. [self setTitleLabelWithTitle:title?:@"分享" WithTextColor:titleColor?:[UIColor blackColor] WithNum:5 withFrame:CGRectMake(wmz_GetWNum(15), wmz_GetHNum(20), self.mainWidth-wmz_GetWNum(30), wmz_GetHNum(31)) isCenter:NO];
  467. UIView *upLine = [self getLineViewWithColor:HEX_COLOR(0x999999) withFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame)+wmz_GetHNum(20), self.mainWidth, 0.5f) withAlpha:0.5f];
  468. [self.mainView addSubview:upLine];
  469. [self.mainView addSubview:self.shareView];
  470. self.shareView.frame = CGRectMake(0, CGRectGetMaxY(upLine.frame)+wmz_GetHNum(20), self.mainWidth , wmz_GetHNum(200));
  471. NSInteger count = [[text allKeys] count];
  472. self.shareView.contentSize = CGSizeMake(count*(self.mainWidth/5)+wmz_GetWNum(40)+(wmz_GetWNum(20)*(count-1)), wmz_GetHNum(200));
  473. UIView *tempView = nil;
  474. for (int i = 0; i<[text allKeys].count; i++) {
  475. NSString *key = [text allKeys][i];
  476. UIView *iconView = nil;
  477. if (i==0) {
  478. iconView = [self shareListIconWithText:key WithImage:text[key] withFrame:CGRectMake(wmz_GetWNum(20), 0, self.mainWidth/5, wmz_GetHNum(200)) withTag:i+1000];
  479. }else{
  480. iconView = [self shareListIconWithText:key WithImage:text[key] withFrame:CGRectMake(CGRectGetMaxX(tempView.frame)+wmz_GetWNum(20), 0, self.mainWidth/5, wmz_GetHNum(200)) withTag:i+1000];
  481. }
  482. tempView = iconView;
  483. [self.shareView addSubview:iconView];
  484. }
  485. UIView *downLine = [self getLineViewWithColor:HEX_COLOR(0x999999) withFrame:CGRectMake(0, CGRectGetMaxY(self.shareView.frame)+wmz_GetHNum(20), self.mainWidth, 0.5f) withAlpha:0.5f];
  486. [self.mainView addSubview:downLine];
  487. [self setCancelBtnWithTextColor:cancelColor withTitle:leftText withFrame:CGRectMake(0, CGRectGetMaxY(downLine.frame), self.mainWidth, wmz_GetHNum(88))];
  488. self.mainView.frame = CGRectMake(wmz_GetWNum(30), kDevice_Height-(CGRectGetMaxY(self.cancelBtn.frame)+wmz_GetHNum(20)), kDevice_Width-wmz_GetWNum(80), CGRectGetMaxY(self.cancelBtn.frame));
  489. return self.mainView;
  490. }
  491. //取消按钮点击事件
  492. - (void)cancelAction:(UIButton*)btn{
  493. if (self.leftButtonClickHandle) {
  494. self.leftButtonClickHandle(self);
  495. }
  496. [self closeView];
  497. }
  498. //确定按钮点击事件
  499. - (void)okAction:(UIButton*)btn{
  500. if (self.rightButtonClickHandle) {
  501. if (self.type==AlertTypeWrite) {
  502. if (self.alertTextView.text.length>0) {
  503. self.rightButtonClickHandle(self.alertTextView.text);
  504. }else{
  505. NSLog(@"输入不能为空");
  506. }
  507. }else if (self.type==AlertTypeSelect){
  508. self.rightButtonClickHandle(self.selectID);
  509. }
  510. else{
  511. self.rightButtonClickHandle(self);
  512. }
  513. }
  514. [self closeView];
  515. }
  516. //关闭按钮点击事件
  517. - (void)closeAction:(UIButton*)btn{
  518. [self closeView];
  519. }
  520. //消失的处理
  521. - (void)closeView{
  522. if ([self.payField isFirstResponder]) {
  523. [self.payField resignFirstResponder];
  524. }
  525. if ([self.alertTextView isFirstResponder]) {
  526. [self.alertTextView resignFirstResponder];
  527. }
  528. if (timer) {
  529. dispatch_source_cancel(timer);
  530. }
  531. [self dismissViewControllerAnimated:YES completion:nil];
  532. }
  533. //textField代理方法
  534. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  535. if (self.type==AlertTypePay) {
  536. if ([NSString stringWithFormat:@"%@%@",textField.text,string].length<=6) {
  537. return YES;
  538. }
  539. return NO;
  540. }
  541. return YES;
  542. }
  543. //textField文字改变时的方法
  544. -(void)textField1TextChange:(UITextField *)textField{
  545. for (int i = 0; i<[self.passView subviews].count; i++) {
  546. UILabel *la = [self.passView subviews][i];
  547. la.text = @"";
  548. }
  549. for (int i = 0; i<textField.text.length; i++) {
  550. UILabel *la = [self.passView viewWithTag:100+i];
  551. la.text = @"●";
  552. }
  553. if (textField.text.length==6) {
  554. if (self.rightButtonClickHandle) {
  555. //此处可以加上正则判断是否都数字
  556. self.rightButtonClickHandle(textField.text);
  557. }
  558. [self closeAction:nil];
  559. }
  560. }
  561. //textVie的代理方法
  562. -(void)textViewDidChange:(UITextView*)textView
  563. {
  564. if([textView.text length] == 0){
  565. self.mainText.text = self.placeHolderText;
  566. }else{
  567. self.mainText.text = @"";//这里给空
  568. }
  569. }
  570. //tableview代理
  571. # pragma mark tableView 代理
  572. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  573. return [UIView new];
  574. }
  575. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  576. return [UIView new];
  577. }
  578. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  579. return 0.01;
  580. }
  581. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  582. return 0.01;
  583. }
  584. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  585. return self.dataArr.count;
  586. }
  587. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  588. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  589. if (!cell) {
  590. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  591. }
  592. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  593. cell.textLabel.text = self.dataArr[indexPath.row];
  594. cell.textLabel.font = [UIFont systemFontOfSize:14];
  595. return cell;
  596. }
  597. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  598. return wmz_GetHNum(70);
  599. }
  600. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  601. self.selectID = self.dataArr[indexPath.row];
  602. }
  603. //键盘将要出现
  604. - (void)keyboardWillShow:(NSNotification *)notification {
  605. NSDictionary *userInfo = notification.userInfo;
  606. CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
  607. switch (self.type) {
  608. case AlertTypePay:
  609. case AlertTypeWrite:
  610. {
  611. self.mainView.frame = CGRectMake(self.mainView.frame.origin.x, kDevice_Height-(endFrame.size.height+wmz_GetHNum(70)+self.mainView.frame.size.height), self.mainView.frame.size.width, self.mainView.frame.size.height);
  612. }
  613. break;
  614. default:
  615. break;
  616. }
  617. }
  618. //获取当前VC
  619. + (UIViewController *)getCurrentVC
  620. {
  621. UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
  622. UIViewController *currentVC = [self getCurrentVCFrom:rootViewController];
  623. return currentVC;
  624. }
  625. + (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC
  626. {
  627. UIViewController *currentVC;
  628. if ([rootVC presentedViewController]) {
  629. // 视图是被presented出来的
  630. rootVC = [rootVC presentedViewController];
  631. }
  632. if ([rootVC isKindOfClass:[UITabBarController class]]) {
  633. // 根视图为UITabBarController
  634. currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]];
  635. } else if ([rootVC isKindOfClass:[UINavigationController class]]){
  636. // 根视图为UINavigationController
  637. currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]];
  638. } else {
  639. // 根视图为非导航类
  640. currentVC = rootVC;
  641. }
  642. return currentVC;
  643. }
  644. //返回文本的size 根据文本的width
  645. + (CGSize)returnSizeWithLabel:(UILabel*)label withRowHeight:(CGFloat)row{
  646. CGSize titleSize = [label.text boundingRectWithSize:CGSizeMake(label.frame.size.width, label.numberOfLines==0?CGFLOAT_MAX:label.numberOfLines*(row+text_Font/3)) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil].size;
  647. return titleSize;
  648. }
  649. //传入 秒 得到 xx:xx:xx
  650. + (NSString *)getMMSSFromSS:(NSString *)totalTime{
  651. NSInteger seconds = [totalTime integerValue];
  652. NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600];
  653. NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60];
  654. NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60];
  655. NSString *format_time = [NSString stringWithFormat:@"%@ : %@ : %@",str_hour,str_minute,str_second];
  656. return format_time;
  657. }
  658. //创建计时器
  659. - (void)createTimer:(NSString *)totalTime{
  660. __block NSInteger seconds = [totalTime integerValue];
  661. __weak typeof(self)weakSelf = self;
  662. dispatch_queue_t global = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  663. timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, global);
  664. dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
  665. dispatch_source_set_event_handler(timer, ^{
  666. seconds --;
  667. if (seconds<=0) {
  668. dispatch_source_cancel(self->timer);
  669. dispatch_async(dispatch_get_main_queue(), ^{
  670. [weakSelf closeView];
  671. });
  672. }else{
  673. dispatch_async(dispatch_get_main_queue(), ^{
  674. weakSelf.mainText.text = [WMZAlert getMMSSFromSS:[NSString stringWithFormat:@"%ld",seconds]];
  675. });
  676. }
  677. });
  678. dispatch_resume(timer);
  679. //如果需要进入后台 定时器也运行的话需要在AppDelegate的enterBackGoround里添加代码 看本项目手动添加
  680. }
  681. /// 懒加载taleview
  682. - (UITableView *)tableView{
  683. if (!_tableView) {
  684. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  685. _tableView.delegate = self;
  686. _tableView.dataSource = self;
  687. _tableView.scrollEnabled = NO;
  688. _tableView.estimatedRowHeight = 0;
  689. _tableView.estimatedSectionHeaderHeight = 0;
  690. _tableView.estimatedSectionFooterHeight = 0;
  691. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  692. }
  693. return _tableView;
  694. }
  695. //标题
  696. - (UILabel *)titleLabel{
  697. if (!_titleLabel) {
  698. _titleLabel = [UILabel new];
  699. _titleLabel.textAlignment = NSTextAlignmentCenter;
  700. _titleLabel.font = [UIFont systemFontOfSize:title_Font];
  701. _titleLabel.numberOfLines = 5;
  702. }
  703. return _titleLabel;
  704. }
  705. //背景
  706. - (UIView *)mainView{
  707. if (!_mainView) {
  708. _mainView = [UIView new];
  709. }
  710. return _mainView;
  711. }
  712. //背景宽度
  713. - (CGFloat)mainWidth{
  714. if (!_mainWidth) {
  715. _mainWidth = self.mainView.frame.size.width;
  716. }
  717. return _mainWidth;
  718. }
  719. //主体文本
  720. - (UILabel *)mainText{
  721. if (!_mainText) {
  722. _mainText = [UILabel new];
  723. _mainText.textAlignment = NSTextAlignmentCenter;
  724. }
  725. return _mainText;
  726. }
  727. //取消按钮
  728. - (UIButton *)cancelBtn{
  729. if (!_cancelBtn) {
  730. _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  731. }
  732. return _cancelBtn;
  733. }
  734. //确定按钮
  735. - (UIButton *)okBtn{
  736. if (!_okBtn) {
  737. _okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  738. }
  739. return _okBtn;
  740. }
  741. //中间线
  742. - (UIView *)leftLine{
  743. if (!_leftLine) {
  744. _leftLine = [UIView new];
  745. _leftLine.alpha = 0.5;
  746. _leftLine.backgroundColor = HEX_COLOR(0x999999);
  747. _leftLine.frame = CGRectMake(CGRectGetMaxX(self.cancelBtn.frame), CGRectGetMinY(self.cancelBtn.frame), 0.5f, wmz_GetHNum(88));
  748. }
  749. return _leftLine;
  750. }
  751. //分享视图
  752. - (UIScrollView *)shareView{
  753. if (!_shareView) {
  754. _shareView = [UIScrollView new];
  755. _shareView.showsVerticalScrollIndicator = NO;
  756. _shareView.showsHorizontalScrollIndicator = NO;
  757. }
  758. return _shareView;
  759. }
  760. //titleLabel 赋值各自属性
  761. - (void)setTitleLabelWithTitle:(NSString*)title WithTextColor:(UIColor*)titleColor WithNum:(NSInteger)num withFrame:(CGRect)frame isCenter:(BOOL)center{
  762. self.titleLabel.textColor = titleColor?:[UIColor blackColor];
  763. self.titleLabel.text = title;
  764. self.titleLabel.font = [UIFont systemFontOfSize:title_Font];
  765. self.titleLabel.numberOfLines = num;
  766. self.titleLabel.frame = frame;
  767. CGSize labelSize = [WMZAlert returnSizeWithLabel:self.titleLabel withRowHeight:frame.size.height];
  768. self.titleLabel.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, labelSize.height);
  769. if (center) {
  770. self.titleLabel.center = CGPointMake(self.mainView.center.x, self.titleLabel.center.y);
  771. }
  772. [self.mainView addSubview:self.titleLabel];
  773. }
  774. //mainView赋值属性
  775. - (void)setMainViewWithColor:(UIColor*)backColor withFrame:(CGRect)frame withRadius:(CGFloat)num{
  776. self.mainView.layer.cornerRadius = num;
  777. self.mainView.layer.masksToBounds = YES;
  778. self.mainView.frame = frame;
  779. self.mainView.backgroundColor = backColor?:[UIColor whiteColor];
  780. }
  781. //mainText赋值
  782. - (void)setMaintextWithText:(NSString*)text WithTextColor:(UIColor*)textColor WithNum:(NSInteger)num withFrame:(CGRect)frame isCenter:(BOOL)center withFont:(UIFont*)font{
  783. self.mainText.textColor = textColor?:[UIColor blackColor];
  784. self.mainText.text = text;
  785. self.mainText.font = font;
  786. self.mainText.numberOfLines = num;
  787. self.mainText.frame = frame;
  788. if (num!=1) {
  789. CGSize LabelSize = [WMZAlert returnSizeWithLabel:self.mainText withRowHeight:frame.size.height];
  790. self.mainText.frame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, LabelSize.height);
  791. }
  792. if (center) {
  793. self.mainText.center = CGPointMake(self.mainView.center.x, self.mainText.center.y);
  794. }
  795. if (self.type==AlertTypeWrite) {
  796. [self.alertTextView addSubview:self.mainText];
  797. self.mainText.textAlignment = NSTextAlignmentLeft;
  798. }else{
  799. [self.mainView addSubview:self.mainText];
  800. }
  801. }
  802. //赋值cancelBtn
  803. - (void)setCancelBtnWithTextColor:(UIColor*)cancelColor withTitle:(NSString*)leftText withFrame:(CGRect)frame{
  804. [self.cancelBtn addTarget:self action:@selector(cancelAction:) forControlEvents:UIControlEventTouchUpInside];
  805. [self.cancelBtn setTitle:leftText?:@"取消" forState:UIControlStateNormal];
  806. [self.cancelBtn setTitleColor:cancelColor?:HEX_COLOR(0x999999) forState:UIControlStateNormal];
  807. self.cancelBtn.backgroundColor = [UIColor whiteColor];
  808. self.cancelBtn.frame = frame;
  809. [self.mainView addSubview:self.cancelBtn];
  810. }
  811. //赋值okbtn
  812. - (void)setOkBtnWithTextColor:(UIColor*)okColor withTitle:(NSString*)rightText withFrame:(CGRect)frame{
  813. self.okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  814. [self.okBtn addTarget:self action:@selector(okAction:) forControlEvents:UIControlEventTouchUpInside];
  815. [self.okBtn setTitle:rightText?:@"确定" forState:UIControlStateNormal];
  816. [self.okBtn setTitleColor:okColor?:HEX_COLOR(0xFD6615) forState:UIControlStateNormal];
  817. self.okBtn.backgroundColor = [UIColor whiteColor];
  818. self.okBtn.frame = frame;
  819. [self.mainView addSubview:self.okBtn];
  820. }
  821. //line
  822. - (UIView*)getLineViewWithColor:(UIColor*)lineColor withFrame:(CGRect)frame withAlpha:(CGFloat)alpha{
  823. UIView *line = [UIView new];
  824. line.alpha = alpha;
  825. line.backgroundColor = lineColor;
  826. line.frame = frame;
  827. return line;
  828. }
  829. //分享子视图
  830. - (UIView*)shareListIconWithText:(NSString*)text WithImage:(NSString*)image withFrame:(CGRect)frame withTag:(NSInteger)tag{
  831. UIView *backView = [UIView new];
  832. backView.frame = frame;
  833. backView.backgroundColor = [UIColor clearColor];
  834. UIImageView *imageView = [UIImageView new];
  835. imageView.frame = CGRectMake(wmz_GetHNum(20), wmz_GetHNum(20), frame.size.width-wmz_GetWNum(40), frame.size.width-wmz_GetWNum(40));
  836. imageView.image = [UIImage imageNamed:image];
  837. imageView.contentMode = UIViewContentModeScaleAspectFill;
  838. imageView.layer.masksToBounds = YES;
  839. imageView.layer.cornerRadius = (frame.size.width-wmz_GetWNum(40))/2;
  840. imageView.clipsToBounds = YES;
  841. imageView.tag = tag;
  842. imageView.userInteractionEnabled = YES;
  843. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageAction:)];
  844. [imageView addGestureRecognizer:tap];
  845. [backView addSubview:imageView];
  846. UILabel *la = [UILabel new];
  847. la.textAlignment = NSTextAlignmentCenter;
  848. la.font = [UIFont systemFontOfSize:text_Font];
  849. la.frame = CGRectMake(0, CGRectGetMaxY(imageView.frame)+wmz_GetHNum(20), frame.size.width, frame.size.height*0.3-wmz_GetHNum(40));
  850. la.text = text;
  851. [backView addSubview:la];
  852. return backView;
  853. }
  854. //重新设置mainView的frame
  855. - (void)reSetMainViewFrame:(CGRect)frame{
  856. self.mainView.frame = frame;
  857. self.mainView.center = self.view.center;
  858. }
  859. //分享视图图片点击
  860. - (void)imageAction:(UITapGestureRecognizer*)sender{
  861. if (self.rightButtonClickHandle) {
  862. UIImageView *image = (UIImageView*)sender.view;
  863. for (int i = 0; i<[self.shareDic allKeys].count; i++) {
  864. if (image.tag-1000==i) {
  865. self.rightButtonClickHandle([self.shareDic allKeys][i]);
  866. [self closeView];
  867. break;
  868. }
  869. }
  870. }
  871. }
  872. @end