HomeHotTalentCell.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // HomeHotTalentCell.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/8/29.
  6. //
  7. #import "HomeHotTalentCell.h"
  8. #import <Lottie/Lottie.h>
  9. @interface HomeHotTalentCell ()
  10. @property (weak, nonatomic) IBOutlet UIImageView *teacherAvatar;
  11. @property (weak, nonatomic) IBOutlet UILabel *teacherName;
  12. @property (weak, nonatomic) IBOutlet UILabel *graduateSchool;
  13. @property (weak, nonatomic) IBOutlet UIView *liveView;
  14. @property (weak, nonatomic) IBOutlet UIView *liveColorView;
  15. @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
  16. @property (weak, nonatomic) IBOutlet UIView *animationBgView;
  17. @property (nonatomic, strong) LOTAnimationView *animationView;
  18. @property (nonatomic, copy) FollowTalentAction callback;
  19. @property (nonatomic, strong) TalentTeacherModel *sourceModel;
  20. @property (weak, nonatomic) IBOutlet UIButton *followButton;
  21. @end
  22. @implementation HomeHotTalentCell
  23. - (void)awakeFromNib {
  24. [super awakeFromNib];
  25. // Initialization code
  26. CAGradientLayer *layer = [self createGradientLayerFromColor:HexRGB(0xFF8B39) startPoint:CGPointMake(0.83, 0.55) endColor:HexRGB(0xFF4046) endPoint:CGPointMake(0.14, 1) bounds:self.liveColorView.bounds];
  27. layer.cornerRadius = 7.0f;
  28. layer.masksToBounds = YES;
  29. [self.liveColorView.layer addSublayer:layer];
  30. [self.liveColorView bringSubviewToFront:self.tipsLabel];
  31. if (![self.animationBgView.subviews containsObject:self.animationView]) {
  32. [self.animationBgView addSubview:self.animationView];
  33. [self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.left.right.top.bottom.mas_equalTo(self.animationBgView);
  35. }];
  36. }
  37. }
  38. - (CAGradientLayer *)createGradientLayerFromColor:(UIColor *)fromColor startPoint:(CGPoint)startPoint endColor:(UIColor *)endColor endPoint:(CGPoint)endPoint bounds:(CGRect)bounds {
  39. CAGradientLayer *gradientLayer = [CAGradientLayer layer];
  40. gradientLayer.colors = @[(__bridge id)fromColor.CGColor, (__bridge id)endColor.CGColor];
  41. gradientLayer.startPoint = startPoint;
  42. gradientLayer.endPoint = endPoint;
  43. gradientLayer.frame = bounds;
  44. gradientLayer.locations = @[@(0),@(1.0f)];
  45. return gradientLayer;
  46. }
  47. - (void)configWithSource:(TalentTeacherModel *)sourceModel callback:(FollowTalentAction)callback {
  48. if (callback) {
  49. self.callback = callback;
  50. }
  51. self.sourceModel = sourceModel;
  52. if (sourceModel.living) {
  53. self.liveView.hidden = NO;
  54. self.animationBgView.hidden = NO;
  55. if ([self.animationView isAnimationPlaying] == NO) {
  56. [self.animationView play];
  57. }
  58. }
  59. else {
  60. self.liveView.hidden = YES;
  61. self.animationBgView.hidden = YES;
  62. if ([self.animationView isAnimationPlaying] == YES) {
  63. [self.animationView stop];
  64. }
  65. }
  66. [self.teacherAvatar sd_setImageWithURL:[NSURL URLWithString:[sourceModel.avatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:TEACHER_AVATAR]];
  67. if ([NSString isEmptyString:sourceModel.username]) {
  68. self.teacherName.text = [NSString stringWithFormat:@"游客%.0f",sourceModel.userId];
  69. }
  70. else {
  71. self.teacherName.text = [NSString stringWithFormat:@"%@",sourceModel.username];
  72. }
  73. if ([NSString isEmptyString:sourceModel.graduateSchool]) {
  74. self.graduateSchool.text = @"认证达人";
  75. }
  76. else {
  77. self.graduateSchool.text = [NSString returnNoNullStringWithString:sourceModel.graduateSchool];
  78. }
  79. if (sourceModel.watch == 1) {
  80. [self setButtonFollowed];
  81. }
  82. else {
  83. self.followButton.userInteractionEnabled = YES;
  84. self.followButton.backgroundColor = THEMECOLOR;
  85. [self.followButton setTitle:@"关注" forState:UIControlStateNormal];
  86. [self.followButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  87. self.followButton.layer.borderColor = THEMECOLOR.CGColor;
  88. }
  89. }
  90. - (void)setButtonFollowed {
  91. self.followButton.userInteractionEnabled = NO;
  92. self.followButton.backgroundColor = [UIColor whiteColor];
  93. [self.followButton setTitle:@"已关注" forState:UIControlStateNormal];
  94. [self.followButton setTitleColor:HexRGB(0x999999) forState:UIControlStateNormal];
  95. self.followButton.layer.borderColor = HexRGB(0xf0f0f0).CGColor;
  96. }
  97. - (IBAction)followAction:(id)sender {
  98. [self setButtonFollowed];
  99. if (self.callback) {
  100. self.callback([NSString stringWithFormat:@"%.0f",self.sourceModel.userId]);
  101. }
  102. }
  103. - (LOTAnimationView *)animationView {
  104. if (!_animationView) {
  105. _animationView = [LOTAnimationView animationWithFilePath:[[NSBundle mainBundle] pathForResource:@"talentAnimation" ofType:@"json"]];
  106. _animationView.loopAnimation = YES;
  107. }
  108. return _animationView;
  109. }
  110. @end