YOUPAIHROldHomeCollectionCell.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // YOUPAIHROldHomeCollectionCell.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/9/28.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHROldHomeCollectionCell.h"
  9. @interface YOUPAIHROldHomeCollectionCell()
  10. @property (nonatomic,strong)UIImageView *youpaipimageV;
  11. @property (nonatomic,strong)UIView *youpaipstatusView;
  12. @property (nonatomic,strong)UIView *youpaipstatusDotView;
  13. @property (nonatomic,strong)UILabel *youpaipstatusLab;
  14. @property (nonatomic,strong)UILabel *youpaipnameLab;
  15. @property (nonatomic,strong)UILabel *signLabel;
  16. @end
  17. @implementation YOUPAIHROldHomeCollectionCell
  18. static NSString* HKHomeCellID = @"YOUPAIHROldHomeCollectionCell";
  19. + (instancetype)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  20. YOUPAIHROldHomeCollectionCell *cell = (YOUPAIHROldHomeCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:HKHomeCellID forIndexPath:indexPath];
  21. return cell;
  22. }
  23. -(id)initWithFrame:(CGRect)frame{
  24. self = [super initWithFrame:frame];
  25. if (self) {
  26. [self youpaifsetupUI];
  27. }
  28. return self;
  29. }
  30. - (void)youpaifsetupUI{
  31. self.contentView.layer.cornerRadius = 5;
  32. self.contentView.layer.masksToBounds = YES;
  33. self.youpaipimageV = [[UIImageView alloc] init];
  34. [self.contentView addSubview:self.youpaipimageV];
  35. [self.youpaipimageV mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.edges.mas_equalTo(0);
  37. }];
  38. self.youpaipimageV.backgroundColor = [LCTools getBkgRandomColor];
  39. self.youpaipimageV.contentMode = UIViewContentModeScaleAspectFill;
  40. UIView *statusView = [[UIView alloc] init];
  41. self.youpaipstatusView = statusView;
  42. [self.youpaipimageV addSubview:statusView];
  43. [statusView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.right.mas_equalTo(-5);
  45. make.width.mas_equalTo(50);
  46. make.top.mas_equalTo(5);
  47. make.height.mas_equalTo(16);
  48. }];
  49. statusView.layer.cornerRadius = 8;
  50. statusView.layer.masksToBounds = YES;
  51. statusView.backgroundColor = HexColorFromRGBA(0x000000,0.37);
  52. self.youpaipstatusDotView = [[UIView alloc] init];
  53. [statusView addSubview:self.youpaipstatusDotView];
  54. [self.youpaipstatusDotView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(4);
  56. make.centerY.mas_equalTo(0);
  57. make.size.mas_equalTo(CGSizeMake(6, 6));
  58. }];
  59. self.youpaipstatusDotView.layer.cornerRadius = 3;
  60. self.youpaipstatusDotView.layer.masksToBounds = YES;
  61. self.youpaipstatusLab = [[UILabel alloc]init];
  62. [self.youpaipstatusView addSubview:self.youpaipstatusLab];
  63. [self.youpaipstatusLab mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.mas_equalTo(self.youpaipstatusDotView.mas_right).offset(2);
  65. make.centerY.mas_equalTo(0);
  66. make.height.mas_equalTo(16);
  67. }];
  68. self.youpaipstatusLab.textColor = HexColorFromRGB(0xFFFFFF);
  69. self.youpaipstatusLab.textAlignment = NSTextAlignmentCenter;
  70. self.youpaipstatusLab.font = LCFont(9);
  71. UIView *footerV = [[UIView alloc] init];
  72. CAGradientLayer *gradientLayerBot = [LCTools getGradientLayerWithSize:footerV.mj_size twoColors:@[[[UIColor blackColor] colorWithAlphaComponent:0.0f],[[UIColor blackColor] colorWithAlphaComponent:0.3f]] gradientType:GradientTopToBottom];
  73. [footerV.layer addSublayer:gradientLayerBot];
  74. [self.contentView addSubview:footerV];
  75. [footerV mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.right.offset(0.0f);
  77. make.bottom.mas_equalTo(0);
  78. make.height.offset(49.0f);
  79. }];
  80. self.youpaipnameLab = [[UILabel alloc]init];
  81. self.youpaipnameLab.textColor = HexColorFromRGB(0xFFFFFF);
  82. self.youpaipnameLab.textAlignment = NSTextAlignmentLeft;
  83. self.youpaipnameLab.font = LCBoldFont(14);
  84. [footerV addSubview:self.youpaipnameLab];
  85. [self.youpaipnameLab makeConstraints:^(MASConstraintMaker *make) {
  86. make.left.offset(10.0f);
  87. make.bottom.offset(-20.0f);
  88. make.height.equalTo(@17);
  89. }];
  90. //个性签名
  91. UILabel *signLabel = [UILabel new];
  92. self.signLabel = signLabel;
  93. [footerV addSubview:signLabel];
  94. [signLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  95. make.left.mas_equalTo(10.0f);
  96. make.right.mas_equalTo(-10.0f);
  97. make.top.mas_equalTo(self.youpaipnameLab.mas_bottom).offset(5);
  98. make.height.mas_equalTo(12);
  99. }];
  100. signLabel.font = [UIFont systemFontOfSize:12];
  101. // signLabel.text = @"好看的皮囊 有趣的灵魂";
  102. signLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  103. signLabel.textColor = [UIColor whiteColor];
  104. self.clipsToBounds = YES;
  105. }
  106. - (void)setYoupaiphomeListModel:(YOUPAILCHomeListModel *)homeListModel{
  107. _youpaiphomeListModel = homeListModel;
  108. [self.youpaipimageV sd_setImageWithURL:[[LCTools getImageUrlWithAddress:homeListModel.youpaipcover] urlWithImageScale:60] placeholderImage:nil];
  109. self.youpaipstatusLab.text = homeListModel.youpaipAddnewMsg;
  110. self.signLabel.text = homeListModel.sign;
  111. CGFloat width = [LCTools widthWithString:homeListModel.youpaipAddnewMsg withFont:LCFont(9)]+15;
  112. [self.youpaipstatusView mas_remakeConstraints:^(MASConstraintMaker *make) {
  113. make.right.mas_equalTo(-5);
  114. make.width.mas_equalTo(width);
  115. make.top.mas_equalTo(5);
  116. make.height.mas_equalTo(16);
  117. }];
  118. self.youpaipstatusDotView.backgroundColor = kColors(homeListModel.youpaipAddnewColor);
  119. [self youpaifsetupShadowWithText:homeListModel.youpaipnickname view:self.youpaipnameLab];
  120. }
  121. - (void)youpaifsetupShadowWithText:(NSString *)text view:(UILabel *)view{
  122. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];
  123. NSShadow *shadow = [[NSShadow alloc]init];
  124. // shadow.shadowBlurRadius = 1.0;
  125. shadow.shadowOffset = CGSizeMake(1, 1.5f);
  126. shadow.shadowColor = [HexColorFromRGB(0x000000) colorWithAlphaComponent:0.2f];
  127. [attributedString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, text.length)];
  128. view.attributedText = attributedString;
  129. }
  130. @end