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.goBtn.hidden = RQ_COMMON_MANAGER.APP_SWITCH;
  39. [[[self.btnArr.rac_sequence.signal deliverOnMainThread] takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(NSString *btnTitleStr) {
  40. @strongify(self)
  41. NSInteger index = [self.btnArr indexOfObject:btnTitleStr];
  42. QMUIButton *btn = [[QMUIButton alloc] initWithFrame:CGRectMake((index * btnWidth) + (space * (((index - 1) > 0)? (index - 1) : 0)), 0, btnWidth, btnHeight)];
  43. [btn setTitleNormal:btnTitleStr];
  44. btn.titleLabel.font = RQMediumFont(14.f);
  45. [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  46. [btn setBackgroundColor:RQ_MAIN_COLOR];
  47. btn.layer.masksToBounds = YES;
  48. btn.layer.cornerRadius = btnHeight / 2.f;
  49. btn.userInteractionEnabled = NO;
  50. [self.placeScrollView addSubview:btn];
  51. self.downArrowImageView.hidden = NO;
  52. } completed:^{
  53. @strongify(self)
  54. self.placeScrollView.contentSize = CGSizeMake((btnWidth * self.btnArr.count) + (space * (((self.btnArr.count - 1) > 0)? (self.btnArr.count - 1) : 0)), btnHeight);
  55. }];
  56. self.downImageViewLeadingToCOntentView.constant = 16.f + (btnWidth / 2.f) - (downImageViewWidth / 2.f);
  57. [self.tipBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  58. graColor.fromColor = RQColorFromHexString(@"#26A1EE");
  59. graColor.toColor = RQColorFromHexString(@"#498EF5");
  60. graColor.type = QQGradualChangeTypeLeftToRight;
  61. } size:CGSizeMake(RQ_FIT_HORIZONTAL(44.f), RQ_FIT_HORIZONTAL(20.f)) cornerRadius:QQRadiusMake(10.f, 0, 0, 10.f)] forState:UIControlStateNormal];
  62. }
  63. - (NSArray *)btnArr {
  64. if (!_btnArr) {
  65. _btnArr = @[@"社会化驾驶人考场"];
  66. }
  67. return _btnArr;
  68. }
  69. @end