AlertMyCartDeleteV.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //
  2. // AlertMyCartDeleteV.m
  3. // westkissMob
  4. //
  5. // Created by 王猛 on 2022/10/19.
  6. //
  7. #import "AlertMyCartDeleteV.h"
  8. @interface AlertMyCartDeleteV (){
  9. UIView * _maskView;
  10. }
  11. @property (nonatomic, strong) UIView *bgView;
  12. @property (nonatomic, strong) UIButton *closeBtn;
  13. @property (nonatomic, strong) QMUILabel *titleLab;
  14. @property (nonatomic, strong) UIButton *yesBtn;
  15. @property (nonatomic, strong) UIButton *noBtn;
  16. @end
  17. @implementation AlertMyCartDeleteV
  18. - (instancetype)initWithPaytypeAlertV:(UIImage *)payImg closeBtnImg:(UIImage *)closeImg{
  19. self = [super init];
  20. if (self) {
  21. [self paytype_addSubViewPayImg:payImg closeBtnImg:closeImg];
  22. }
  23. return self;
  24. }
  25. - (void)dealTap:(UITapGestureRecognizer *)tap{
  26. [self alertv_remove];
  27. }
  28. -(void)paytype_addSubViewPayImg:(UIImage *)payImg closeBtnImg:(UIImage *)closeImg{
  29. self.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
  30. _maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
  31. _maskView.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.8];
  32. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dealTap:)];
  33. [_maskView addGestureRecognizer:tap];
  34. [self addSubview:_maskView];
  35. UIImageView *payImgV = [[UIImageView alloc]initWithImage:payImg];
  36. payImgV.frame = CGRectMake(0, 0, payImg.size.width, payImg.size.height);
  37. payImgV.center = self.center;
  38. payImgV.userInteractionEnabled = YES;
  39. [self addSubview:payImgV];
  40. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  41. closeBtn.frame = CGRectMake((payImgV.mj_w-40)/2, 10, 40, 40);
  42. [closeBtn setImage:closeImg forState:UIControlStateNormal];
  43. [closeBtn addTarget:self action:@selector(handle_closeBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
  44. [payImgV addSubview:closeBtn];
  45. }
  46. -(void)handle_closeBtnEvent:(UIButton *)btn{
  47. [self alertv_remove];
  48. }
  49. -(void)alertv_show{
  50. [[UIApplication sharedApplication].keyWindow addSubview:self];
  51. }
  52. -(void)alertv_remove{
  53. [_maskView removeFromSuperview];
  54. [self removeFromSuperview];
  55. }
  56. - (instancetype)initWithYesBtnAlertVtitle:(NSString *)titile yesTitle:(NSString *)btnTitle;{
  57. self = [super init];
  58. if (self) {
  59. [self tt_setupViews];
  60. [self alertTitleYesBtn_AddsubViews:titile yesTitle:btnTitle];
  61. }
  62. return self;
  63. }
  64. #pragma mark - **************** 特殊方法 alertTitleYesBtn ****************
  65. -(void)alertTitleYesBtn_AddsubViews:(NSString *)title yesTitle:(NSString *)btnTitle{
  66. [self.bgView addSubview:self.titleLab];
  67. [self.bgView addSubview:self.yesBtn];
  68. self.titleLab.font = [UIFont fontWithName:Rob_Regular size:14];
  69. self.titleLab.text = title;
  70. self.yesBtn.backgroundColor = [UIColor colorWithHexString:@"#000000"];
  71. self.yesBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  72. [self.yesBtn setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  73. NSAttributedString *btnStr = [[NSAttributedString alloc] initWithString:btnTitle];
  74. [self.yesBtn setAttributedTitle:btnStr forState:UIControlStateNormal];
  75. [self.yesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.width.mas_equalTo(132);
  77. make.height.mas_equalTo(35);
  78. make.centerX.mas_equalTo(0);
  79. make.bottom.mas_equalTo(-30);
  80. }];
  81. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.top.equalTo(self.closeBtn.mas_bottom).offset(20);
  83. make.left.mas_equalTo(20);
  84. make.width.mas_equalTo(KScreenWidth -70-40);
  85. make.bottom.equalTo(self.yesBtn.mas_top).offset(-20);
  86. }];
  87. }
  88. - (instancetype)initWithAlertVtitle:(NSMutableAttributedString *)titile{
  89. self = [super init];
  90. if (self) {
  91. [self tt_setupViews];
  92. [self alertTitle_AddSubViews:titile];
  93. }
  94. return self;
  95. }
  96. #pragma mark - **************** 特殊方法 alertTitle_****************
  97. -(void)alertTitle_AddSubViews:(NSMutableAttributedString *)title{
  98. [self.bgView addSubview:self.titleLab];
  99. [self.bgView addSubview:self.yesBtn];
  100. [self.bgView addSubview:self.noBtn];
  101. [self alertTitle_titleVFrameWithTitle:title];
  102. }
  103. -(void)alertTitle_titleVFrameWithTitle:(NSMutableAttributedString *)title{
  104. CGSize maxsize = CGSizeMake((KScreenWidth -70-40),MAXFLOAT);
  105. [title addAttribute:NSFontAttributeName
  106. value:[UIFont fontWithName:Rob_Bold size:14]
  107. range:NSMakeRange(0, title.length)];
  108. CGFloat labelHeight = [title boundingRectWithSize:maxsize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size.height;
  109. self.titleLab.attributedText = title;
  110. self.titleLab.textAlignment = NSTextAlignmentCenter;
  111. [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.top.equalTo(self.closeBtn.mas_bottom).offset(20);
  113. make.left.mas_equalTo(20);
  114. make.width.mas_equalTo(KScreenWidth -70-40);
  115. make.height.mas_equalTo(labelHeight + 40);
  116. }];
  117. [self.noBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.width.mas_equalTo(120);
  119. make.height.mas_equalTo(35);
  120. make.centerX.mas_equalTo(0);
  121. make.top.equalTo(self.titleLab.mas_bottom).offset(20);
  122. make.bottom.mas_equalTo(-30);
  123. }];
  124. [self.yesBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.right.equalTo(self.noBtn.mas_left).offset(-15);
  126. make.top.equalTo(self.titleLab.mas_bottom).offset(20);
  127. make.height.mas_equalTo(35);
  128. make.width.mas_equalTo(35);
  129. }];
  130. }
  131. #pragma mark - **************** 公共方法 ****************
  132. - (void)tt_setupViews{
  133. self.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
  134. self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.3];
  135. [[UIApplication sharedApplication].keyWindow addSubview:self];
  136. [self addSubview:self.bgView];
  137. [self.bgView addSubview:self.closeBtn];
  138. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  139. make.left.mas_equalTo(35);
  140. make.right.mas_equalTo(-35);
  141. make.centerY.mas_equalTo(0);
  142. make.height.mas_equalTo(200);
  143. }];
  144. [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  145. make.top.mas_equalTo(20);
  146. make.width.height.mas_equalTo(40);
  147. make.centerX.mas_equalTo(0);
  148. }];
  149. }
  150. #pragma mark - **************** handle ****************
  151. -(void)handle_CloseViewEvent:(UIButton *)btn{
  152. [self removeFromSuperview];
  153. }
  154. -(void)handle_yesClickEvent:(UIButton *)btn{
  155. if (self.ViewtapClose) {
  156. self.ViewtapClose(1, @"");
  157. }
  158. [self removeFromSuperview];
  159. }
  160. -(void)handle_noClickEvent:(UIButton *)btn{
  161. if (self.ViewtapClose) {
  162. self.ViewtapClose(0, @"");
  163. }
  164. [self removeFromSuperview];
  165. }
  166. -(UIView *)bgView{
  167. if(!_bgView){
  168. _bgView = [[UIView alloc]init];
  169. _bgView.backgroundColor = [UIColor colorWithHexString:@"#FFDEE2"];
  170. }
  171. return _bgView;
  172. }
  173. -(UIButton *)closeBtn{
  174. if(!_closeBtn){
  175. _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  176. [_closeBtn setImage:[UIImage imageNamed:@"base_close_black"] forState:UIControlStateNormal];
  177. [_closeBtn addTarget:self action:@selector(handle_CloseViewEvent:) forControlEvents:UIControlEventTouchUpInside];
  178. }
  179. return _closeBtn;
  180. }
  181. -(QMUILabel *)titleLab{
  182. if(!_titleLab){
  183. _titleLab = [[QMUILabel alloc]init];
  184. _titleLab.textAlignment = NSTextAlignmentCenter;
  185. _titleLab.font = [UIFont fontWithName:Rob_Bold size:14];
  186. }
  187. return _titleLab;
  188. }
  189. -(UIButton *)yesBtn{
  190. if(!_yesBtn){
  191. _yesBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  192. _yesBtn.backgroundColor = [UIColor clearColor];
  193. [_yesBtn setTitle:@"YES" forState:UIControlStateNormal];
  194. [_yesBtn setTitleColor:Col_000 forState:UIControlStateNormal];
  195. [_yesBtn addTarget:self action:@selector(handle_yesClickEvent:) forControlEvents:UIControlEventTouchUpInside];
  196. NSMutableAttributedString *noString = [[NSMutableAttributedString alloc] initWithString:@"YES"];
  197. [noString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [noString length])];
  198. [_yesBtn setAttributedTitle:noString forState:UIControlStateNormal];
  199. _yesBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  200. }
  201. return _yesBtn;
  202. }
  203. -(UIButton *)noBtn{
  204. if(!_noBtn){
  205. _noBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  206. _noBtn.backgroundColor = Col_000;
  207. [_noBtn setTitleColor:Col_FFF forState:UIControlStateNormal];
  208. [_noBtn addTarget:self action:@selector(handle_noClickEvent:) forControlEvents:UIControlEventTouchUpInside];
  209. NSMutableAttributedString *noString = [[NSMutableAttributedString alloc] initWithString:@"NO"];
  210. [noString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [noString length])];
  211. [_noBtn setAttributedTitle:noString forState:UIControlStateNormal];
  212. _noBtn.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
  213. }
  214. return _noBtn;
  215. }
  216. @end