YOUPAILZVideoDiscountWindow.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // YOUPAILZVideoDiscountWindow.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/7/16.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZVideoDiscountWindow.h"
  9. @interface YOUPAILZVideoDiscountWindow ()
  10. @property (nonatomic,strong) NSArray <UIButton *>*youpaipbtns;
  11. @property (nonatomic,assign) NSInteger youpaipcurrentIndex;
  12. @end
  13. @implementation YOUPAILZVideoDiscountWindow
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. self.baseView.hidden = YES;
  17. [self youpaifinitUI];
  18. }
  19. - (void)youpaifinitUI{
  20. UIView *bgV = [[UIView alloc] init];
  21. bgV.backgroundColor = [UIColor whiteColor];
  22. bgV.layer.cornerRadius = 10.0f;
  23. bgV.clipsToBounds = YES;
  24. [self.view addSubview:bgV];
  25. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.left.offset(32.0f);
  27. make.right.offset(-32.0f);
  28. make.centerY.equalTo(self.view.mas_centerY);
  29. }];
  30. UILabel *titleL = [[UILabel alloc] init];
  31. titleL.textColor = HexColorFromRGB(0x333333);
  32. titleL.font = LCBFont17;
  33. titleL.textAlignment = NSTextAlignmentCenter;
  34. titleL.text = @"你可以减免对方的时长费用";
  35. [bgV addSubview:titleL];
  36. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.offset(14.0f);
  38. make.right.offset(-14.0f);
  39. make.top.offset(20.0f);
  40. }];
  41. UILabel *subtitleL = [[UILabel alloc] init];
  42. subtitleL.textColor = HexColorFromRGB(0x9F9DA5);
  43. subtitleL.font = LCFont(14.0f);
  44. subtitleL.textAlignment = NSTextAlignmentCenter;
  45. subtitleL.text = [NSString stringWithFormat:@"当前视频价格为:%@钻石/每分钟",self.youpaipmodel.youpaipprice];
  46. [bgV addSubview:subtitleL];
  47. [subtitleL mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.offset(14.0f);
  49. make.right.offset(-14.0f);
  50. make.top.equalTo(titleL.mas_bottom).offset(6.0f);
  51. }];
  52. NSInteger colCount = 3;
  53. NSInteger totalRow = (self.youpaipmodel.youpaiptime.count + colCount - 1) / colCount;
  54. CGFloat height = 33.0f * totalRow + (totalRow - 1) * 12.0f;
  55. UIView *timerBgV = [[UIView alloc] init];
  56. [bgV addSubview:timerBgV];
  57. [timerBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.left.offset(14.0f);
  59. make.right.offset(-14.0f);
  60. make.top.equalTo(subtitleL.mas_bottom).offset(25.0f);
  61. make.height.offset(height);
  62. }];
  63. CGFloat btnWidth = (KScreenWidth - 90.0f + 12.0f) / colCount;
  64. self.youpaipcurrentIndex = 0;
  65. NSMutableArray <UIButton *>*btns = [NSMutableArray array];
  66. for (NSInteger i = 0; i < self.youpaipmodel.youpaiptime.count; i ++) {
  67. NSInteger col = i % colCount;
  68. NSInteger row = i / colCount;
  69. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  70. btn.frame = CGRectMake(col * btnWidth, row * 33.0f + row * 12.0f, btnWidth - 12.0f, 33.0f);
  71. btn.layer.cornerRadius = 16.5f;
  72. btn.clipsToBounds = YES;
  73. btn.layer.borderColor = LZF5F4F7Color.CGColor;
  74. btn.layer.borderWidth = 1.0f;
  75. btn.backgroundColor = LZF5F4F7Color;
  76. [btn setTitle:self.youpaipmodel.youpaiptime[i].youpaiptime forState:UIControlStateNormal];
  77. [btn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  78. [btn setTitleColor:LZ7C69FEColor forState:UIControlStateSelected];
  79. btn.titleLabel.font = LCFont14;
  80. btn.tag = i;
  81. if (i == self.youpaipcurrentIndex) {
  82. btn.selected = YES;
  83. btn.backgroundColor = [LZ7C69FEColor colorWithAlphaComponent:0.1f];
  84. btn.layer.borderColor = LZ7C69FEColor.CGColor;
  85. }
  86. [btn addTarget:self action:@selector(youpaifitemClick:) forControlEvents:UIControlEventTouchUpInside];
  87. [timerBgV addSubview:btn];
  88. [btns addObject:btn];
  89. }
  90. self.youpaipbtns = btns.copy;
  91. CGFloat width = (KScreenWidth-90.0f-15.0f) / 2.0f;
  92. UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  93. cancelBtn.layer.cornerRadius = 24.0f;
  94. cancelBtn.clipsToBounds = YES;
  95. cancelBtn.backgroundColor = LZF5F4F7Color;
  96. [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
  97. [cancelBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  98. cancelBtn.titleLabel.font = LCFont17;
  99. [cancelBtn addTarget:self action:@selector(youpaifcancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
  100. [bgV addSubview:cancelBtn];
  101. [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.offset(14.0f);
  103. make.top.equalTo(timerBgV.mas_bottom).offset(40.0f);
  104. make.size.mas_offset(CGSizeMake(width, 48.0f));
  105. make.bottom.offset(-20.0f);
  106. }];
  107. UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  108. confirmBtn.layer.cornerRadius = 24.0f;
  109. confirmBtn.clipsToBounds = YES;
  110. [confirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(width, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  111. [confirmBtn setTitle:@"确认" forState:UIControlStateNormal];
  112. [confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  113. confirmBtn.titleLabel.font = LCFont17;
  114. [confirmBtn addTarget:self action:@selector(youpaifconfirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
  115. [bgV addSubview:confirmBtn];
  116. [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.right.offset(-14.0f);
  118. make.size.mas_offset(CGSizeMake(width, 48.0f));
  119. make.bottom.offset(-20.0f);
  120. }];
  121. }
  122. - (void)youpaifitemClick:(UIButton *)sender{
  123. UIButton *btn = self.youpaipbtns[self.youpaipcurrentIndex];
  124. btn.selected = NO;
  125. btn.layer.borderColor = LZF5F4F7Color.CGColor;
  126. btn.backgroundColor = LZF5F4F7Color;
  127. self.youpaipcurrentIndex = sender.tag;
  128. sender.selected = YES;
  129. sender.backgroundColor = [LZ7C69FEColor colorWithAlphaComponent:0.1f];
  130. sender.layer.borderColor = LZ7C69FEColor.CGColor;
  131. }
  132. - (void)youpaifcancelBtnClick{
  133. [self dismissViewControllerAnimated:YES completion:nil];
  134. }
  135. - (void)youpaifconfirmBtnClick{
  136. if (self.confirmBtnClickBlock && self.youpaipmodel.youpaiptime.count != 0) {
  137. self.confirmBtnClickBlock(self.youpaipmodel.youpaiptime[self.youpaipcurrentIndex]);
  138. }
  139. [self dismissViewControllerAnimated:YES completion:nil];
  140. }
  141. @end