MOAddBlackAlertView.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. //
  2. // MOAddBlackAlertView.m
  3. // MiMoLive
  4. //
  5. // Created by MiMo on 2025/6/24.
  6. //
  7. //时长(1=30分钟,2=24小时,3=3天,4=7天,5=永久) ps:新增黑名单时,字段非空
  8. #define kMOAddBlackAlerViewWidth 295
  9. #import "MOAddBlackAlertView.h"
  10. @interface MOAddBlackAlertView ()
  11. @property (nonatomic, strong) UIView *backgroundView;
  12. @property (nonatomic, strong) UIView *contentView;
  13. @property (nonatomic, strong) UILabel *titleLabel;
  14. @property (nonatomic, strong) UILabel *descLabel;
  15. @property (nonatomic, strong) UIStackView *stackView;
  16. @property (nonatomic, strong) UIButton *oneDayButton;
  17. @property (nonatomic, strong) UIButton *sevenDayButton;
  18. @property (nonatomic, strong) UIButton *foreverButton;
  19. @property (nonatomic, strong) UIButton *cancelButton;
  20. @property (nonatomic, strong) UIButton *confirmButton;
  21. @property (nonatomic, assign) NSInteger timeIndex;
  22. @end
  23. @implementation MOAddBlackAlertView
  24. - (instancetype)init {
  25. if (self = [super init]) {
  26. [self setupUI];
  27. [self initData];
  28. }
  29. return self;
  30. }
  31. - (void)initData {
  32. self.timeIndex = 5;//默认选中永久选项,==5
  33. self.foreverButton.selected = YES;
  34. }
  35. - (void)setupUI {
  36. [self addSubview:self.backgroundView];
  37. [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.edges.mas_equalTo(0);
  39. }];
  40. [self addSubview:self.contentView];
  41. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.center.mas_equalTo(0);
  43. make.width.mas_equalTo(kMOAddBlackAlerViewWidth);
  44. make.height.mas_equalTo(224);
  45. }];
  46. [self.contentView addSubview:self.titleLabel];
  47. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.mas_equalTo(24);
  49. make.centerX.mas_equalTo(0);
  50. make.height.mas_equalTo(26);
  51. }];
  52. [self.contentView addSubview:self.descLabel];
  53. [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
  55. make.left.mas_equalTo(20);
  56. make.right.mas_equalTo(-20);
  57. }];
  58. [self.contentView addSubview:self.stackView];
  59. [self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(self.descLabel.mas_bottom).offset(12);
  61. make.left.mas_equalTo(20);
  62. make.right.mas_equalTo(-20);
  63. make.height.mas_equalTo(28);
  64. }];
  65. [self.stackView addArrangedSubview:self.oneDayButton];
  66. [self.stackView addArrangedSubview:self.sevenDayButton];
  67. [self.stackView addArrangedSubview:self.foreverButton];
  68. [self.contentView addSubview:self.cancelButton];
  69. [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.mas_equalTo(20);
  71. make.bottom.mas_equalTo(-24);
  72. make.size.mas_equalTo(CGSizeMake(113, 36));
  73. }];
  74. [self.contentView addSubview:self.confirmButton];
  75. [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.right.mas_equalTo(-20);
  77. make.centerY.equalTo(self.cancelButton);
  78. make.size.mas_equalTo(CGSizeMake(113, 36));
  79. }];
  80. }
  81. - (void)show {
  82. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  83. [keyWindow addSubview:self];
  84. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  85. [self updateContentViewHeight];
  86. //动画效果
  87. self.contentView.transform = CGAffineTransformMakeScale(1.1, 1.1);
  88. [UIView animateWithDuration:0.2 animations:^ {
  89. self.contentView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  90. } completion:nil];
  91. }
  92. - (void)updateContentViewHeight {
  93. CGFloat descHeight = [MOTools getSizeFrom:self.descLabel.text font:self.descLabel.font maxSize:CGSizeMake(kMOAddBlackAlerViewWidth - 40, MAXFLOAT)].height;
  94. [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
  95. make.height.mas_equalTo(descHeight + 170);//170是其他控件和间距的总和
  96. }];
  97. }
  98. - (void)dismiss {
  99. [UIView animateWithDuration:0.2 animations:^ {
  100. self.contentView.transform = CGAffineTransformMakeScale(1.1, 1.1);
  101. self.contentView.alpha = 0.0;
  102. } completion:^(BOOL finished) {
  103. if (finished) {
  104. [self removeFromSuperview];
  105. }
  106. }];
  107. }
  108. - (void)cancelButtonAction {
  109. [self dismiss];
  110. }
  111. - (void)confirmButtonAction {
  112. if (self.addBlackConfirmBlock) {
  113. self.addBlackConfirmBlock(self.timeIndex);
  114. }
  115. [self dismiss];
  116. }
  117. - (void)selectedTimeButton:(UIButton *)button {
  118. self.oneDayButton.selected = NO;
  119. self.sevenDayButton.selected = NO;
  120. self.foreverButton.selected = NO;
  121. self.oneDayButton.layer.borderWidth = 0;
  122. self.sevenDayButton.layer.borderWidth = 0;
  123. self.foreverButton.layer.borderWidth = 0;
  124. button.selected = YES;
  125. self.timeIndex = button.tag;
  126. button.layer.borderWidth = 1;
  127. }
  128. #pragma mark - Lazy
  129. - (UIView *)backgroundView {
  130. if (!_backgroundView) {
  131. _backgroundView = [[UIView alloc] init];
  132. _backgroundView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.4];
  133. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
  134. [_backgroundView addGestureRecognizer:tap];
  135. }
  136. return _backgroundView;
  137. }
  138. - (UIView *)contentView {
  139. if (!_contentView) {
  140. _contentView = [[UIView alloc] init];
  141. _contentView.layer.masksToBounds = YES;
  142. _contentView.layer.cornerRadius = 16;
  143. _contentView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
  144. }
  145. return _contentView;
  146. }
  147. - (UILabel *)titleLabel {
  148. if (!_titleLabel) {
  149. _titleLabel = [[UILabel alloc] init];
  150. _titleLabel.text = NSLocalString(@"mimo_2_black_title");
  151. _titleLabel.font = [MOTextTools mediumFont:16];
  152. _titleLabel.textColor = kBaseTextColor_1;
  153. _titleLabel.numberOfLines = 0;
  154. }
  155. return _titleLabel;
  156. }
  157. - (UILabel *)descLabel {
  158. if (!_descLabel) {
  159. _descLabel = [[UILabel alloc] init];
  160. _descLabel.text = NSLocalString(@"mimo_2_black_desc");
  161. _descLabel.font = [MOTextTools regularFont:13];
  162. _descLabel.textColor = kBaseTextColor_2;
  163. _descLabel.numberOfLines = 0;
  164. }
  165. return _descLabel;
  166. }
  167. - (UIStackView *)stackView {
  168. if (!_stackView) {
  169. _stackView = [[UIStackView alloc] init];
  170. _stackView.axis = UILayoutConstraintAxisHorizontal;
  171. _stackView.distribution = UIStackViewDistributionFillEqually;
  172. _stackView.spacing = 15;
  173. }
  174. return _stackView;
  175. }
  176. - (UIButton *)oneDayButton {
  177. if (!_oneDayButton) {
  178. _oneDayButton = [[UIButton alloc] init];
  179. [_oneDayButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
  180. [_oneDayButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateSelected];
  181. [_oneDayButton setTitle:NSLocalString(@"mimo_2_black_one_day") forState:UIControlStateNormal];
  182. _oneDayButton.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
  183. _oneDayButton.titleLabel.font = [MOTextTools regularFont:12];
  184. _oneDayButton.layer.masksToBounds = YES;
  185. _oneDayButton.layer.cornerRadius = 14;
  186. _oneDayButton.layer.borderColor = [MOTools colorWithHexString:@"#4363FF"].CGColor;
  187. _oneDayButton.layer.borderWidth = 0.0;
  188. _oneDayButton.tag = 2;
  189. [_oneDayButton addTarget:self action:@selector(selectedTimeButton:) forControlEvents:UIControlEventTouchUpInside];
  190. }
  191. return _oneDayButton;
  192. }
  193. - (UIButton *)sevenDayButton {
  194. if (!_sevenDayButton) {
  195. _sevenDayButton = [[UIButton alloc] init];
  196. [_sevenDayButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
  197. [_sevenDayButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateSelected];
  198. [_sevenDayButton setTitle:NSLocalString(@"mimo_2_black_seven_day") forState:UIControlStateNormal];
  199. _sevenDayButton.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
  200. _sevenDayButton.titleLabel.font = [MOTextTools regularFont:12];
  201. _sevenDayButton.layer.masksToBounds = YES;
  202. _sevenDayButton.layer.cornerRadius = 14;
  203. _sevenDayButton.layer.borderColor = [MOTools colorWithHexString:@"#4363FF"].CGColor;
  204. _sevenDayButton.layer.borderWidth = 0.0;
  205. _sevenDayButton.tag = 4;
  206. [_sevenDayButton addTarget:self action:@selector(selectedTimeButton:) forControlEvents:UIControlEventTouchUpInside];
  207. }
  208. return _sevenDayButton;
  209. }
  210. - (UIButton *)foreverButton {
  211. if (!_foreverButton) {
  212. _foreverButton = [[UIButton alloc] init];
  213. [_foreverButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
  214. [_foreverButton setTitleColor:[MOTools colorWithHexString:@"#4363FF"] forState:UIControlStateSelected];
  215. [_foreverButton setTitle:NSLocalString(@"mimo_back_pack_permanent") forState:UIControlStateNormal];
  216. _foreverButton.backgroundColor = [MOTools colorWithHexString:@"#F3F4FA"];
  217. _foreverButton.titleLabel.font = [MOTextTools regularFont:12];
  218. _foreverButton.layer.masksToBounds = YES;
  219. _foreverButton.layer.cornerRadius = 14;
  220. _foreverButton.layer.borderColor = [MOTools colorWithHexString:@"#4363FF"].CGColor;
  221. _foreverButton.layer.borderWidth = 1.0;
  222. _foreverButton.tag = 5;
  223. [_foreverButton addTarget:self action:@selector(selectedTimeButton:) forControlEvents:UIControlEventTouchUpInside];
  224. }
  225. return _foreverButton;
  226. }
  227. - (UIButton *)cancelButton {
  228. if (!_cancelButton) {
  229. _cancelButton = [[UIButton alloc] init];
  230. [_cancelButton setTitle:NSLocalString(@"mimo_common_cancel") forState:UIControlStateNormal];
  231. [_cancelButton setTitleColor:kBaseTextColor_1 forState:UIControlStateNormal];
  232. _cancelButton.titleLabel.font = [MOTextTools regularFont:16];
  233. _cancelButton.layer.cornerRadius = 12;
  234. _cancelButton.layer.masksToBounds = YES;
  235. _cancelButton.layer.borderColor = [MOTools colorWithHexString:@"#DADCE6"].CGColor;
  236. _cancelButton.layer.borderWidth = 1;
  237. [_cancelButton addTarget:self action:@selector(cancelButtonAction) forControlEvents:UIControlEventTouchUpInside];
  238. }
  239. return _cancelButton;
  240. }
  241. - (UIButton *)confirmButton {
  242. if (!_confirmButton) {
  243. _confirmButton = [[UIButton alloc] init];
  244. [_confirmButton setTitle:NSLocalString(@"mimo_common_confirm") forState:UIControlStateNormal];
  245. [_confirmButton setTitleColor:[MOTools colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
  246. _confirmButton.titleLabel.font = [MOTextTools regularFont:16];
  247. NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
  248. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, 127, 36) Colors:colorArr GradientType:0];
  249. [_confirmButton setBackgroundImage:image forState:UIControlStateNormal];
  250. _confirmButton.layer.cornerRadius = 12;
  251. _confirmButton.layer.masksToBounds = YES;
  252. [_confirmButton addTarget:self action:@selector(confirmButtonAction) forControlEvents:UIControlEventTouchUpInside];
  253. }
  254. return _confirmButton;
  255. }
  256. @end