RQVipReminderCell.m 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // RQVipReminderCell.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/9/19.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQVipReminderCell.h"
  9. @interface RQVipReminderCell ()
  10. @property (nonatomic, readwrite, strong) RQVipReminderItemViewModel *viewModel;
  11. @property (weak, nonatomic) IBOutlet YYTextView *oneLabel;
  12. @property (weak, nonatomic) IBOutlet YYTextView *twoLabel;
  13. @property (nonatomic, readwrite, strong) NSMutableAttributedString *spaceAttachment;
  14. @end
  15. @implementation RQVipReminderCell
  16. #pragma mark - PublicMethods
  17. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  18. static NSString *ID = @"RQVipReminderCell";
  19. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  20. RQVipReminderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  21. if (!cell) cell = [self rq_viewFromXib];
  22. [cell borderColor:RQColorFromHexString(@"#E0B279") width:1 cornorRadius:5];
  23. return cell;
  24. }
  25. - (void)bindViewModel:(RQVipReminderItemViewModel *)viewModel {
  26. // @weakify(self)
  27. _viewModel = viewModel;
  28. }
  29. - (void)setIndexPath:(NSIndexPath *)indexPath rowsInSection:(NSInteger)rows {
  30. self.backgroundColor = RQColorFromHexString(@"#252531");
  31. }
  32. #pragma mark - SystemMethods
  33. - (void)awakeFromNib {
  34. [super awakeFromNib];
  35. _oneLabel.attributedText = [self dealStrWithAllStr:@"VIP题库主要面向 学习C1/C2的学员 进行编制,其他准驾车型的学员可根据自身需求购买!" str:@"学习C1/C2的学员" font:14];
  36. _twoLabel.attributedText = [self dealStrWithAllStr:@"购买VIP课程是巩固培训成果, 将提升考试通过率 。" str:@"将提升考试通过率" font:13];
  37. }
  38. #pragma mark - PrivateMethods
  39. - (NSMutableAttributedString *)dealStrWithAllStr:(NSString *)allStr str:(NSString *)str font:(NSInteger)font {
  40. NSMutableAttributedString *text = [NSMutableAttributedString new];
  41. NSMutableAttributedString *testText = [NSMutableAttributedString new];
  42. NSArray *allStrArr = [allStr componentsSeparatedByString:str];
  43. NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:allStrArr.firstObject];
  44. attrString1.yy_font = [UIFont systemFontOfSize:font];
  45. attrString1.yy_color = [UIColor qmui_colorWithHexString:@"#F8DEB8"];
  46. [testText appendAttributedString: attrString1];
  47. NSMutableAttributedString *typeAttachment = nil;
  48. QMUIButton *typeBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  49. CGFloat btnHeight = RQ_FIT_HORIZONTAL(22.f);
  50. CGFloat btnWeight = [str widthForFont:[UIFont systemFontOfSize:font]] + 8.f;
  51. CGFloat btnCornerRadius = 5;
  52. CGSize btnSize = CGSizeMake(btnWeight, btnHeight);
  53. typeBtn.size = btnSize;
  54. [typeBtn setTitle:str textColor:[UIColor qmui_colorWithHexString:@"#91540F"] Font:font fotState:UIControlStateNormal];
  55. [typeBtn setBackgroundImage:[UIImage qmui_imageWithColor:[UIColor qmui_colorWithHexString:@"#F8DEB8"] size:btnSize cornerRadiusArray:@[@(btnCornerRadius), @(btnCornerRadius), @(btnCornerRadius), @(btnCornerRadius)]] forState:UIControlStateNormal];
  56. typeAttachment = [NSMutableAttributedString yy_attachmentStringWithContent:typeBtn
  57. contentMode:UIViewContentModeCenter
  58. attachmentSize:btnSize
  59. alignToFont:[UIFont systemFontOfSize:font]
  60. alignment:YYTextVerticalAlignmentCenter];
  61. [testText appendAttributedString:typeAttachment];
  62. // [testText appendAttributedString:self.spaceAttachment];
  63. NSMutableAttributedString *attrString2 = [[NSMutableAttributedString alloc] initWithString:allStrArr.lastObject];
  64. attrString2.yy_font = [UIFont systemFontOfSize:font];
  65. attrString2.yy_color = [UIColor qmui_colorWithHexString:@"#F8DEB8"];
  66. [testText appendAttributedString: attrString2];
  67. [text appendAttributedString:testText];
  68. text.yy_lineSpacing = 8;
  69. return text;
  70. }
  71. - (NSMutableAttributedString *)spaceAttachment {
  72. if (!_spaceAttachment) {
  73. UIView *spaceView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 4, 25)];
  74. _spaceAttachment = [NSMutableAttributedString yy_attachmentStringWithContent:spaceView contentMode:UIViewContentModeCenter attachmentSize:CGSizeMake(4, 25) alignToFont:[UIFont boldSystemFontOfSize:RQ_Exercise_Module.exerciseFontSize] alignment:YYTextVerticalAlignmentCenter];
  75. }
  76. return _spaceAttachment;
  77. }
  78. @end