123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // HomeHotTalentCell.m
- // KulexiuForStudent
- //
- // Created by 王智 on 2022/8/29.
- //
- #import "HomeHotTalentCell.h"
- #import <Lottie/Lottie.h>
- @interface HomeHotTalentCell ()
- @property (weak, nonatomic) IBOutlet UIImageView *teacherAvatar;
- @property (weak, nonatomic) IBOutlet UILabel *teacherName;
- @property (weak, nonatomic) IBOutlet UILabel *graduateSchool;
- @property (weak, nonatomic) IBOutlet UIView *liveView;
- @property (weak, nonatomic) IBOutlet UIView *liveColorView;
- @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
- @property (weak, nonatomic) IBOutlet UIView *animationBgView;
- @property (nonatomic, strong) LOTAnimationView *animationView;
- @property (nonatomic, copy) FollowTalentAction callback;
- @property (nonatomic, strong) TalentTeacherModel *sourceModel;
- @end
- @implementation HomeHotTalentCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- CAGradientLayer *layer = [self createGradientLayerFromColor:HexRGB(0xFF8B39) startPoint:CGPointMake(0.83, 0.55) endColor:HexRGB(0xFF4046) endPoint:CGPointMake(0.14, 1) bounds:self.liveColorView.bounds];
- layer.cornerRadius = 7.0f;
- layer.masksToBounds = YES;
- [self.liveColorView.layer addSublayer:layer];
- [self.liveColorView bringSubviewToFront:self.tipsLabel];
-
- if (![self.animationBgView.subviews containsObject:self.animationView]) {
- [self.animationBgView addSubview:self.animationView];
- [self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self.animationBgView);
- }];
- }
- }
- - (CAGradientLayer *)createGradientLayerFromColor:(UIColor *)fromColor startPoint:(CGPoint)startPoint endColor:(UIColor *)endColor endPoint:(CGPoint)endPoint bounds:(CGRect)bounds {
- CAGradientLayer *gradientLayer = [CAGradientLayer layer];
- gradientLayer.colors = @[(__bridge id)fromColor.CGColor, (__bridge id)endColor.CGColor];
- gradientLayer.startPoint = startPoint;
- gradientLayer.endPoint = endPoint;
- gradientLayer.frame = bounds;
- gradientLayer.locations = @[@(0),@(1.0f)];
- return gradientLayer;
- }
- - (void)configWithSource:(TalentTeacherModel *)sourceModel callback:(FollowTalentAction)callback {
- if (callback) {
- self.callback = callback;
- }
- self.sourceModel = sourceModel;
- if (sourceModel.living) {
- self.liveView.hidden = NO;
- self.animationBgView.hidden = NO;
- if ([self.animationView isAnimationPlaying] == NO) {
- [self.animationView play];
- }
- }
- else {
- self.liveView.hidden = YES;
- self.animationBgView.hidden = YES;
- if ([self.animationView isAnimationPlaying] == YES) {
- [self.animationView stop];
- }
- }
- [self.teacherAvatar sd_setImageWithURL:[NSURL URLWithString:[sourceModel.avatar getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
- if ([NSString isEmptyString:sourceModel.username]) {
- self.teacherName.text = [NSString stringWithFormat:@"游客%.0f",sourceModel.userId];
- }
- else {
- self.teacherName.text = [NSString stringWithFormat:@"%@",sourceModel.username];
- }
-
- if ([NSString isEmptyString:sourceModel.graduateSchool]) {
- self.graduateSchool.text = @"认证达人";
- }
- else {
- self.graduateSchool.text = [NSString returnNoNullStringWithString:sourceModel.graduateSchool];
- }
-
- }
- - (IBAction)followAction:(id)sender {
- if (self.callback) {
- self.callback([NSString stringWithFormat:@"%.0f",self.sourceModel.userId]);
- }
- }
- - (LOTAnimationView *)animationView {
- if (!_animationView) {
- _animationView = [LOTAnimationView animationNamed:@"talentAnimation.json"];
- _animationView.loopAnimation = YES;
- }
- return _animationView;
- }
- @end
|