// // YOUPAILZBarrageGradientVipNotifactionCell.m // VQU // // Created by CY on 2021/10/21. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZBarrageGradientVipNotifactionCell.h" @implementation YOUPAILZBarrageGradientVipNotifactionCell - (instancetype)init { self = [super init]; if (self) { self.userInteractionEnabled = YES; } return self; } - (void)prepareForReuse { [super prepareForReuse]; //因为在点击的时候被改为了红色, 所以在重用的时候, 要重置一下颜色 } - (void)setBarrageDescriptor:(YOUPAIOCBarrageDescriptor *)barrageDescriptor { [super setBarrageDescriptor:barrageDescriptor]; self.des = (YOUPAIOCBarrageTextDescriptor *)barrageDescriptor; } - (void)youpaifupdateSubviewsData { [super youpaifupdateSubviewsData]; for (UIView *subview in self.subviews) { [subview removeFromSuperview]; } self.backgroundColor = [UIColor clearColor]; self.dataModel = self.des.dataModel; UIView *bgV = [[UIView alloc] init]; bgV.layer.cornerRadius = 15.0f; bgV.clipsToBounds = YES; bgV.backgroundColor = [HexColorFromRGB(0xC440E3) colorWithAlphaComponent:0.3f]; [self addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.height.offset(30.0f); // make.centerY.equalTo(self); make.left.offset(0.0f); }]; UIImageView *vipImgV = [[UIImageView alloc] init]; vipImgV.contentMode = UIViewContentModeScaleAspectFit; [vipImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:self.dataModel.vip_icon]]; [bgV addSubview:vipImgV]; [vipImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(bgV); make.right.offset(-7.0f); make.size.mas_offset(CGSizeMake(30.0f, 19.0f)); }]; UILabel *contentL = [[UILabel alloc] init]; contentL.font = LCBoldFont(13.0f); contentL.textColor = [UIColor whiteColor]; contentL.text = [NSString stringWithFormat:@"恭喜 %@ 成为贵族",self.dataModel.nickname]; NSMutableAttributedString *attributedText=[[NSMutableAttributedString alloc]initWithString:contentL.text]; NSRange range = [contentL.text rangeOfString:self.dataModel.nickname]; [attributedText addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xFFDD8D) range:range]; contentL.attributedText = attributedText.copy; [bgV addSubview:contentL]; [contentL mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(7.0f); make.centerY.equalTo(bgV); make.right.equalTo(vipImgV.mas_left).offset(-5.0f); }]; [self layoutIfNeeded]; } - (void)layoutSubviews { [super layoutSubviews]; } - (void)youpaiflayoutContentSubviews { [super youpaiflayoutContentSubviews]; } - (void)youpaifconvertContentToImage { /* UIImage *contentImage = [self.layer youpaifconvertContentToImageWithSize:CGSizeMake(CGRectGetMaxX(self.backView.frame), CGRectGetMaxY(self.backView.frame))]; [self.layer setContents:(__bridge id)contentImage.CGImage]; */ } - (void)removeSubViewsAndSublayers { //如果不要删除leftImageView, middleImageView, rightImageView, textLabel, 只需重写这个方法并留空就可以了. //比如: 你想在这个cell被点击的时候, 修改文本颜色 // _gradientLayer = nil; } - (void)youpaifaddBarrageAnimationWithDelegate:(id)animationDelegate { if (!self.superview) { return; } CGPoint startCenter = CGPointMake(CGRectGetMaxX(self.superview.bounds) + CGRectGetWidth(self.bounds)/2, self.center.y); CGPoint stopCenter = CGPointMake((CGRectGetWidth(self.bounds)/2) + 20, self.center.y); CGPoint endCenter = CGPointMake(-(CGRectGetWidth(self.bounds)/2), self.center.y); ///* CAKeyframeAnimation *walkAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; walkAnimation.values = @[[NSValue valueWithCGPoint:startCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:stopCenter], [NSValue valueWithCGPoint:endCenter]]; walkAnimation.keyTimes = @[@(0.0), @(0.35), @(0.75), @(1.0)]; walkAnimation.duration = self.barrageDescriptor.animationDuration; walkAnimation.repeatCount = 1; walkAnimation.delegate = animationDelegate; walkAnimation.removedOnCompletion = NO; walkAnimation.fillMode = kCAFillModeForwards; [self.layer addAnimation:walkAnimation forKey:kBarrageAnimation]; } //- (void)addGradientLayerWithBackView:(UIView *)backView{ // if (!self.des.gradientColor) { // return; // } // [self layoutIfNeeded]; // // CAGradientLayer *gradientLayer = [CAGradientLayer layer]; // gradientLayer.colors = @[ // (__bridge id)[HexColorFromRGB(0xC440E3) colorWithAlphaComponent:0.3f].CGColor, // (__bridge id)[HexColorFromRGB(0xC440E3) colorWithAlphaComponent:0.3f].CGColor, // (__bridge id)[(color) colorWithAlphaComponent:0.0].CGColor // ]; // gradientLayer.locations = @[@0.2,@0.6,@1.0]; // gradientLayer.startPoint = CGPointMake(0, 0); // gradientLayer.endPoint = CGPointMake(1.0, 0); // gradientLayer.frame = CGRectMake(0.0, 0.0, backView.frame.size.width, backView.frame.size.height); // // UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:gradientLayer.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(0, 0)]; // CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; // maskLayer.frame = gradientLayer.bounds; // maskLayer.path = maskPath.CGPath; // gradientLayer.mask = maskLayer; // _gradientLayer = gradientLayer; // [backView.layer insertSublayer:gradientLayer atIndex:0]; //} @end