RQTeachSchoolVideoCell.m 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // RQTeachSchoolVideoCell.m
  3. // JiaPei
  4. //
  5. // Created by 张嵘 on 2023/4/6.
  6. //
  7. #import "RQTeachSchoolVideoCell.h"
  8. @interface RQTeachSchoolVideoCell ()
  9. @property (nonatomic, readwrite, strong) RQTeachSchoolVideoItemViewModel *viewModel;
  10. @property (weak, nonatomic) IBOutlet QMUIButton *goBtn;
  11. @property (weak, nonatomic) IBOutlet QMUIButton *myGoBtn;
  12. @property (weak, nonatomic) IBOutlet UIScrollView *placeScrollView;
  13. @property (weak, nonatomic) IBOutlet UIImageView *downArrowImageView;
  14. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *downImageViewLeadingToCOntentView;
  15. @property (weak, nonatomic) IBOutlet QMUIButton *tipBtn;
  16. @property (nonatomic, readwrite, copy) NSArray *btnArr;
  17. @end
  18. @implementation RQTeachSchoolVideoCell
  19. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  20. static NSString *ID = @"RQTeachSchoolVideoCell";
  21. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  22. RQTeachSchoolVideoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  23. if (!cell) cell = [self rq_viewFromXib];
  24. cell.goBtn.layer.cornerRadius = RQ_FIT_HORIZONTAL(46.f) / 2.f;
  25. cell.myGoBtn.imagePosition = QMUIButtonImagePositionRight;
  26. return cell;
  27. }
  28. - (void)bindViewModel:(RQTeachSchoolVideoItemViewModel *)viewModel {
  29. _viewModel = viewModel;
  30. }
  31. - (void)awakeFromNib {
  32. [super awakeFromNib];
  33. @weakify(self)
  34. CGFloat btnWidth = (RQ_SCREEN_WIDTH - 32.f) * (134.f / 345.f);
  35. CGFloat btnHeight = btnWidth * (32.f / 134.f);
  36. CGFloat downImageViewWidth = (RQ_SCREEN_WIDTH - 32.f) * (18.f / 345.f);
  37. CGFloat space = 10.f;
  38. [[[self.btnArr.rac_sequence.signal deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(NSString *btnTitleStr) {
  39. @strongify(self)
  40. NSInteger index = [self.btnArr indexOfObject:btnTitleStr];
  41. QMUIButton *btn = [[QMUIButton alloc] initWithFrame:CGRectMake((index * btnWidth) + (space * (((index - 1) > 0)? (index - 1) : 0)), 0, btnWidth, btnHeight)];
  42. [btn setTitleNormal:btnTitleStr];
  43. btn.titleLabel.font = RQMediumFont(14.f);
  44. [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  45. [btn setBackgroundColor:RQ_MAIN_COLOR];
  46. btn.layer.masksToBounds = YES;
  47. btn.layer.cornerRadius = btnHeight / 2.f;
  48. btn.userInteractionEnabled = NO;
  49. [self.placeScrollView addSubview:btn];
  50. self.downArrowImageView.hidden = NO;
  51. } completed:^{
  52. @strongify(self)
  53. self.placeScrollView.contentSize = CGSizeMake((btnWidth * self.btnArr.count) + (space * (((self.btnArr.count - 1) > 0)? (self.btnArr.count - 1) : 0)), btnHeight);
  54. }];
  55. self.downImageViewLeadingToCOntentView.constant = 16.f + (btnWidth / 2.f) - (downImageViewWidth / 2.f);
  56. [self.tipBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  57. graColor.fromColor = RQColorFromHexString(@"#26A1EE");
  58. graColor.toColor = RQColorFromHexString(@"#498EF5");
  59. graColor.type = QQGradualChangeTypeLeftToRight;
  60. } size:CGSizeMake(RQ_FIT_HORIZONTAL(44.f), RQ_FIT_HORIZONTAL(20.f)) cornerRadius:QQRadiusMake(10.f, 0, 0, 10.f)] forState:UIControlStateNormal];
  61. }
  62. - (NSArray *)btnArr {
  63. if (!_btnArr) {
  64. _btnArr = @[@"社会化驾驶人考场"];
  65. }
  66. return _btnArr;
  67. }
  68. @end