MOChooseTimeAlertView.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // MOChooseTimeAlertView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/12/13.
  6. //
  7. #import "MOChooseTimeAlertView.h"
  8. @interface MOChooseTimeAlertView ()<UICollectionViewDelegate,UICollectionViewDataSource>
  9. @property (weak, nonatomic) IBOutlet UIView *bgView;
  10. @property (weak, nonatomic) IBOutlet UILabel *titleLab;
  11. @property (weak, nonatomic) IBOutlet UILabel *topTipLab;
  12. @property (weak, nonatomic) IBOutlet UILabel *bottomTipLab;
  13. @property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
  14. @property (weak, nonatomic) IBOutlet UIButton *cancelBtn;
  15. @property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
  16. @end
  17. @implementation MOChooseTimeAlertView
  18. + (instancetype)moChooseTimeAlertView{
  19. return [[[NSBundle mainBundle] loadNibNamed:@"MOChooseTimeAlertView" owner:self options:nil] firstObject];
  20. }
  21. - (void)awakeFromNib{
  22. [super awakeFromNib];
  23. self.titleLab.text = NSLocalString(@"mimo_room_confirm_title");
  24. self.bgView.layer.cornerRadius = 16.0;
  25. self.bgView.layer.masksToBounds = YES;
  26. self.cancelBtn.layer.cornerRadius = 50.0 / 2.0;
  27. self.cancelBtn.layer.masksToBounds = YES;
  28. self.cancelBtn.layer.borderColor = [MOTools colorWithHexString:@"#B7B6B6" alpha:1.0].CGColor;
  29. self.cancelBtn.layer.borderWidth = 1.0;
  30. [self.cancelBtn setTitle:NSLocalString(@"mimo_Cancel") forState:UIControlStateNormal];
  31. CGFloat imgWidth = (SCREENWIDTH - 10.0 * 2.0 - 17.0 * 2.0 - 15.0) / 2.0;
  32. self.confirmBtn.layer.cornerRadius = 50.0 / 2.0;
  33. self.confirmBtn.layer.masksToBounds = YES;
  34. NSArray *colorArr = @[kBaseBtnBgColor,kBaseBtnBgColor];
  35. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, imgWidth, 50.0) Colors:colorArr GradientType:0];
  36. [self.confirmBtn setBackgroundImage:image forState:UIControlStateNormal];
  37. [self.confirmBtn setTitle:NSLocalString(@"mimo_TipConfirm") forState:UIControlStateNormal];
  38. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
  39. CGFloat width = (SCREENWIDTH - 10.0 * 2 - 15.0 * 2 - 9.0 * 2) / 3.0;
  40. CGFloat height = 35.0;
  41. flow.itemSize = CGSizeMake(width, height);
  42. flow.minimumLineSpacing = 10.0;//行间距
  43. flow.minimumInteritemSpacing = 8.0;//列间距
  44. flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  45. [self.collectionView setCollectionViewLayout:flow];
  46. self.collectionView.delegate = self;
  47. self.collectionView.dataSource = self;
  48. self.collectionView.backgroundColor = [MOTools colorWithHexString:@"#F9F9F9" alpha:1.0];
  49. [self.collectionView registerClass:[MOChooseTimeCell class] forCellWithReuseIdentifier:MOChooseTimeCell_ID];
  50. self.selectIndex = 0;
  51. }
  52. #pragma mark - Set
  53. - (void)setDataArr:(NSArray *)dataArr{
  54. _dataArr = dataArr;
  55. [self.collectionView reloadData];
  56. }
  57. - (void)setTitleText:(NSString *)titleText{
  58. _titleText = titleText;
  59. self.titleLab.text = titleText;
  60. }
  61. - (void)setTopTipText:(NSString *)topTipText{
  62. _topTipText = topTipText;
  63. self.topTipLab.text = topTipText;
  64. }
  65. - (void)setBottomTipText:(NSString *)bottomTipText{
  66. _bottomTipText = bottomTipText;
  67. if(bottomTipText.length == 0){
  68. self.bottomTipLab.hidden = YES;
  69. }
  70. else{
  71. self.bottomTipLab.hidden = NO;
  72. self.bottomTipLab.text = bottomTipText;
  73. }
  74. }
  75. #pragma mark UICollectionViewDelegate,UICollectionViewDataSource
  76. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  77. return 1;
  78. }
  79. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  80. return self.dataArr.count;
  81. }
  82. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  83. NSString *cellStr = self.dataArr[indexPath.row];
  84. MOChooseTimeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MOChooseTimeCell_ID forIndexPath:indexPath];
  85. cell.titleLab.text = cellStr;
  86. if(self.selectIndex == indexPath.row){
  87. cell.isChoose = YES;
  88. }
  89. else{
  90. cell.isChoose = NO;
  91. }
  92. return cell;
  93. }
  94. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  95. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  96. if(self.selectIndex + 1 <= self.dataArr.count){
  97. self.selectIndex = indexPath.row;
  98. [self.collectionView reloadData];
  99. }
  100. }
  101. #pragma mark - Show
  102. - (IBAction)dismissBtnClick:(id)sender {
  103. [self dismissChooseTimeAlertView];
  104. }
  105. - (IBAction)cancelBtnClick:(id)sender {
  106. [self dismissChooseTimeAlertView];
  107. }
  108. - (IBAction)confirmBtnClick:(id)sender {
  109. self.confirmBtnBlock ? self.confirmBtnBlock(self.selectIndex) : nil;
  110. [self dismissChooseTimeAlertView];
  111. }
  112. - (void)showChooseTimeAlertView//界面显示动画
  113. {
  114. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  115. [keyWindow addSubview:self];
  116. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  117. //动画效果
  118. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  119. self.bgView.alpha = 0;
  120. [UIView animateWithDuration:0.2 animations:^
  121. {
  122. self.bgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  123. self.bgView.alpha = 1;
  124. } completion:^(BOOL finished)
  125. {
  126. }];
  127. }
  128. - (void)dismissChooseTimeAlertView//取消掉键盘
  129. {
  130. [UIView animateWithDuration:0.2 animations:^
  131. {
  132. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  133. self.bgView.alpha = 0;
  134. } completion:^(BOOL finished)
  135. {
  136. if (finished)
  137. {
  138. [self.bgView removeFromSuperview];
  139. [self removeFromSuperview];
  140. }
  141. }];
  142. }
  143. @end