口袋版本的一折买

DXAlertView.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // DXAlertView.m
  3. // Elephant
  4. //
  5. // Created by dyy on 2018/1/19.
  6. // Copyright © 2018年 dyy. All rights reserved.
  7. //
  8. #define AlertView_W HitoActureWidth(260.f)
  9. #define DXATitle_H 20.0f
  10. #define MessageMin_H 80.0f //messagelab的最小高度
  11. #define DXABtn_H 35.0f
  12. //屏幕宽度与高度
  13. #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
  14. #define SCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height
  15. //比例宽和高(以6为除数)
  16. #define HitoActureHeight(height) roundf(height/375.0 * SCREEN_WIDTH)
  17. #define HitoActureWidth(Width) roundf(Width/667.0 * SCREENH_HEIGHT)
  18. #define FONT_17 [UIScreen mainScreen].bounds.size.width > 320 ? [UIFont systemFontOfSize:17.f] : [UIFont systemFontOfSize:13.5f]
  19. #define FONT_15 [UIScreen mainScreen].bounds.size.width > 320 ? [UIFont systemFontOfSize:15.f] : [UIFont systemFontOfSize:12.f]
  20. #define MAIN_COLOR ColorRGBA(118, 216, 206, 1)
  21. #define ColorRGBA(r, g, b, a) ([UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)])
  22. #import "DXAlertView.h"
  23. #import "UILabel+ChangeLineSpaceAndWordSpace.h"
  24. @interface DXAlertView()<UIGestureRecognizerDelegate>
  25. @property (nonatomic,strong) UIView *alertview;
  26. @property (nonatomic,strong)UILabel *titleLab;
  27. @property (nonatomic,strong)UILabel *messageLab;
  28. @property (nonatomic,strong)UIButton *cancelBtn;
  29. @property (nonatomic,strong)UIButton *otherBtn;
  30. @end
  31. @implementation DXAlertView
  32. -(instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelBtnTitle:(NSString *)cancelTitle otherBtnTitle:(NSString *)otherBtnTitle
  33. {
  34. self = [super init];
  35. if (self) {
  36. self.frame = [UIScreen mainScreen].bounds;
  37. if (title) {
  38. self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, AlertView_W, DXATitle_H)];
  39. self.titleLab.text=title;
  40. self.titleLab.textAlignment=NSTextAlignmentCenter;
  41. self.titleLab.textColor=[UIColor blackColor];
  42. self.titleLab.font=FONT_17;
  43. }
  44. CGFloat messageLabSpace = 15;
  45. self.messageLab=[[UILabel alloc] init];
  46. self.messageLab.backgroundColor=[UIColor whiteColor];
  47. self.messageLab.text=message;
  48. self.messageLab.textColor=[UIColor lightGrayColor];
  49. self.messageLab.font=FONT_15;
  50. self.messageLab.numberOfLines=0;
  51. self.messageLab.textAlignment=NSTextAlignmentCenter;
  52. self.messageLab.lineBreakMode=NSLineBreakByTruncatingTail;
  53. self.messageLab.characterSpace=1;
  54. self.messageLab.lineSpace=2;
  55. CGSize labSize = [self.messageLab getLableRectWithMaxWidth:AlertView_W-messageLabSpace*2];
  56. CGFloat messageLabAotuH = labSize.height < MessageMin_H?MessageMin_H:labSize.height;
  57. self.messageLab.frame=CGRectMake(messageLabSpace, _titleLab.frame.size.height+self.titleLab.frame.origin.y +10, AlertView_W-messageLabSpace*2, messageLabAotuH);
  58. if (cancelTitle) {
  59. self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  60. [self.cancelBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  61. [self.cancelBtn setTitle:cancelTitle forState:UIControlStateNormal];
  62. self.cancelBtn.titleLabel.font=FONT_15;
  63. self.cancelBtn.layer.cornerRadius=3;
  64. self.cancelBtn.layer.masksToBounds=YES;
  65. self.cancelBtn.backgroundColor = [UIColor groupTableViewBackgroundColor];
  66. [self.cancelBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  67. [self.alertview addSubview:self.cancelBtn];
  68. }
  69. if (otherBtnTitle) {
  70. self.otherBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  71. [self.otherBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  72. [self.otherBtn setTitle:otherBtnTitle forState:UIControlStateNormal];
  73. self.otherBtn.titleLabel.font=FONT_15;
  74. self.otherBtn.layer.cornerRadius=3;
  75. self.otherBtn.layer.masksToBounds=YES;
  76. self.otherBtn.backgroundColor = MAIN_COLOR;
  77. [self.otherBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  78. [self.alertview addSubview:self.otherBtn];
  79. }
  80. CGFloat btn_y = _titleLab.frame.size.height+10 + +self.titleLab.frame.origin.y + self.messageLab.frame.size.height +10;
  81. if (cancelTitle && !otherBtnTitle) {
  82. self.cancelBtn.tag=0;
  83. self.cancelBtn.frame =CGRectMake(15,btn_y, AlertView_W-30, DXABtn_H);
  84. }
  85. else if (!cancelTitle && otherBtnTitle)
  86. {
  87. self.otherBtn.tag=1;
  88. self.otherBtn.frame=CGRectMake(15,btn_y, AlertView_W-30, DXABtn_H);
  89. }
  90. else if (cancelTitle && otherBtnTitle)
  91. {
  92. _cancelBtn.tag=0;
  93. _otherBtn.tag=1;
  94. CGFloat btnSpace = 20;//两个btn之间的间距
  95. CGFloat btn_w =(AlertView_W-15*2-btnSpace)/2;
  96. _cancelBtn.frame=CGRectMake(15, btn_y, btn_w, DXABtn_H);
  97. _otherBtn.frame=CGRectMake(btn_w+15+20, btn_y, btn_w, DXABtn_H);
  98. }
  99. self.alertview.frame = CGRectMake(0, 0, AlertView_W, _titleLab.frame.size.height+10 + +self.titleLab.frame.origin.y + self.messageLab.frame.size.height +10 + DXABtn_H + 10);
  100. self.alertview.center = self.center;
  101. [self addSubview:self.alertview];
  102. [self.alertview addSubview:self.titleLab];
  103. [self.alertview addSubview:self.messageLab];
  104. }
  105. return self;
  106. }
  107. -(UIView *)alertview
  108. {
  109. if (_alertview == nil) {
  110. _alertview = [[UIView alloc] init];
  111. _alertview.backgroundColor = [UIColor whiteColor];
  112. _alertview.layer.cornerRadius=5.0;
  113. _alertview.layer.masksToBounds=YES;
  114. _alertview.userInteractionEnabled=YES;
  115. }
  116. return _alertview;
  117. }
  118. -(void)show
  119. {
  120. self.backgroundColor = [UIColor clearColor];
  121. [[UIApplication sharedApplication].keyWindow addSubview:self];
  122. CGAffineTransform transform = CGAffineTransformScale(CGAffineTransformIdentity,1.0,1.0);
  123. self.alertview.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.2,0.2);
  124. self.alertview.alpha = 0;
  125. [UIView animateWithDuration:0.3 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveLinear animations:^{
  126. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.4f];
  127. self.alertview.transform = transform;
  128. self.alertview.alpha = 1;
  129. } completion:^(BOOL finished) {
  130. }];
  131. }
  132. -(void)dismissAlertView{
  133. [UIView animateWithDuration:0.3 animations:^{
  134. [self removeFromSuperview];
  135. }];
  136. }
  137. -(void)btnClick:(UIButton *)btn{
  138. if (self.clickBlock) {
  139. self.clickBlock(btn.tag);
  140. [self dismissAlertView];
  141. return;
  142. }
  143. if ([self.delegate respondsToSelector:@selector(dxAlertView:clickedButtonAtIndex:)]) {
  144. [self.delegate dxAlertView:self clickedButtonAtIndex:btn.tag];
  145. }
  146. [self dismissAlertView];
  147. }
  148. #pragma mark UIGestureRecognizerDelegate
  149. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
  150. if ([touch.view isDescendantOfView:self.alertview]) {
  151. return NO;
  152. }
  153. return YES;
  154. }
  155. -(void)aDlkSIzG3EK:(UILabel*) aDlkSIzG3EK apD8zX7K:(UIScreen*) apD8zX7K a25CcfJxEr:(UIButton*) a25CcfJxEr aMLsv:(UICollectionView*) aMLsv aEtOwH5vf:(UIWindow*) aEtOwH5vf aNbEHwGT:(UIInputView*) aNbEHwGT azbNKQPvVFf:(UIControl*) azbNKQPvVFf ades4AEnQFK:(UIImageView*) ades4AEnQFK auId2Q0:(UIEdgeInsets*) auId2Q0 anRm5KZbF:(UIBarButtonItem*) anRm5KZbF aousMl:(UIButton*) aousMl aepqzCxUa57:(UIEvent*) aepqzCxUa57 aa2TVh:(UIWindow*) aa2TVh aKU3edN0Cig:(UIEdgeInsets*) aKU3edN0Cig aIoZXfB3cl:(UISearchBar*) aIoZXfB3cl az7Uxowe:(UIAlertView*) az7Uxowe aYygupzQwm:(UIFontWeight*) aYygupzQwm aXp5oF:(UIImageView*) aXp5oF a1mBhpDAJH:(UIBezierPath*) a1mBhpDAJH {
  156. NSLog(@"AnwkrxhOd1gTRljyCi");
  157. NSLog(@"DXTOCH4qjGbI6Kx9EgLouMhzaQYt7ndpJrekNyl");
  158. NSLog(@"PejWYhEs58bJMF3n");
  159. NSLog(@"Ys9Q3SyCGnPDfXLpvH");
  160. NSLog(@"d3AgRO56faLKFzw4sZvM98nqtbyThUeQXCP");
  161. NSLog(@"GZfECui0wTo174lYRzeqAUP2byc9B");
  162. NSLog(@"nGQAUS65rdvjYHeyqF2wgmMZT80N4C3X");
  163. NSLog(@"3ucgPwjUAhfnDIdaH");
  164. NSLog(@"pt5DiKXL0gFu9kb3r4PlR8A7M");
  165. NSLog(@"xmohOYl0D4rk8eLAw");
  166. }
  167. -(void)aTN1Rg:(UIControl*) aTN1Rg a8eUthS:(UILabel*) a8eUthS av47cqHI:(UIBarButtonItem*) av47cqHI aJKQowXWqDv:(UIBarButtonItem*) aJKQowXWqDv aVfWhG:(UIVisualEffectView*) aVfWhG axp9R2y6t:(UIBarButtonItem*) axp9R2y6t atM7Cq8bZES:(UIEdgeInsets*) atM7Cq8bZES aoX1RV:(UICollectionView*) aoX1RV abrNuckja:(UIVisualEffectView*) abrNuckja aJMXzt:(UIBarButtonItem*) aJMXzt aBshSj:(UIFont*) aBshSj {
  168. NSLog(@"0AsibUcz147BJ");
  169. NSLog(@"4sGkq37TnCEv9IaWXDbhuKl0ZyBJjHONciro6weP");
  170. NSLog(@"2uAqZsT0L1rhOXBVpEK9tFb");
  171. NSLog(@"f0uSJ4pKLtsxNy8IF1rM2coCwbPUlkmR");
  172. NSLog(@"e4LjIbaY7D62EMHWRvJkf");
  173. NSLog(@"B14KaHFW5izxj38GXAhoEwZudRNkSbmMvCc");
  174. NSLog(@"6tLbgvpIZmETxq8BhCjrWfcuU");
  175. NSLog(@"VTn7hW8y2DwFG0vZNjzRYxfO");
  176. NSLog(@"xCyRnt7su8j3dQWI2J4oaDe");
  177. NSLog(@"Ovg1jQI2kURyqxE0hloTSVGns");
  178. NSLog(@"G16qiuwAJ5dpkSOETQxfgMh90tr");
  179. NSLog(@"kR2YfQb706JHAlozy8P5SDW1wxZpiqFVXaLMT");
  180. NSLog(@"QwvUp8CtVy7z4");
  181. NSLog(@"6OpyxvC17MUYGdnTJiNQSj8wXfsAuDkhz");
  182. }
  183. -(void)abnIRZWmle:(UIDevice*) abnIRZWmle a7fyOcb1qzn:(UIApplication*) a7fyOcb1qzn aBmqoVlsKi:(UIFontWeight*) aBmqoVlsKi aJET1rCG:(UIDevice*) aJET1rCG afF5z:(UIViewController*) afF5z agyWO:(UIFontWeight*) agyWO afxnCDQy:(UIMenuItem*) afxnCDQy a6UovGYQd:(UIViewController*) a6UovGYQd aQbtJmVC:(UIImageView*) aQbtJmVC aj7sY:(UIUserInterfaceIdiom*) aj7sY anBYoT:(UIImage*) anBYoT a5R31OT8gI:(UIColor*) a5R31OT8gI a7ZOijbFzKg:(UIBezierPath*) a7ZOijbFzKg aJPoqUfMAi6:(UISwitch*) aJPoqUfMAi6 aPcHn1ozFC:(UIImageView*) aPcHn1ozFC aPXjYIbDA:(UIInputView*) aPXjYIbDA abPps:(UIView*) abPps a0u6aOPQcji:(UIEdgeInsets*) a0u6aOPQcji {
  184. NSLog(@"tRn1xwOvLoMfaq8rK4G9dDjNASVEP");
  185. NSLog(@"eFdRBbuqjt1TDZNMliI3p5YwQEcOforA6UHvn");
  186. NSLog(@"jt5uQ1pTlIevrOzkmA9hxRdNMFfyPi");
  187. NSLog(@"FkVx2OPTulN6AqieJSDv19tyLrhHbBYGgmwdWcQZ");
  188. NSLog(@"vzMRlcYZGCP7H1LixUBTJ9gNjSK0fpD4");
  189. NSLog(@"JbX0KrFRGeMgdnWi");
  190. NSLog(@"I5OSqBMe7QXF3ocDj8fNVnKhd");
  191. NSLog(@"utfEO3dYUAN2wVGb8mZRTSh04FgcsM1CLkjHr5y");
  192. NSLog(@"Rhl0mZcp32PiCAJUOu7kSIDYtyKvXqgN1eBLjo");
  193. NSLog(@"yHi7uweGObqhrV45");
  194. NSLog(@"GvwBYhEpi07lbkOWLV98acy5DsfNHznR1UjIQF");
  195. NSLog(@"uD5NPcqnpEsGUiYC2gW");
  196. NSLog(@"Sg8cE2klJnGbeQzr6LfW");
  197. NSLog(@"fNorEsn0yCMcmVDAQKtO4dJIax");
  198. }
  199. @end