// // QXGiftScrollView.m // QXLive // // Created by 启星 on 2025/5/13. // #import "QXGiftScrollView.h" #import static NSInteger maxCount = 5; @interface QXGiftScrollView() @property (nonatomic,strong)SDCycleScrollView *cycleScrollView; @property (nonatomic,strong)NSMutableArray *dataArray; @property (nonatomic,strong)NSMutableArray *titles; @end @implementation QXGiftScrollView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; } return self; } -(void)initSubViews{ // [self addRoundedCornersWithRadius:15.5]; // self.layer.borderWidth = 2; // self.layer.borderColor = RGB16(0x333333).CGColor; self.backgroundColor = UIColor.clearColor; self.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.bounds delegate:self placeholderImage:nil]; self.cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone; self.cycleScrollView.scrollDirection = UICollectionViewScrollDirectionVertical; self.cycleScrollView.delegate = self; self.cycleScrollView.backgroundColor = UIColor.clearColor; [self addSubview:self.cycleScrollView]; } -(void)setModel:(QXGiftScrollModel *)model{ _model = model; [self.dataArray insertObject:model atIndex:0]; [self.titles insertObject:model.fromUserName atIndex:0]; if (self.dataArray.count > 5) { [self.dataArray removeLastObject]; [self.titles removeLastObject]; } self.cycleScrollView.imageURLStringsGroup = self.titles; } -(void)setList:(NSArray *)list{ _list = list; if (list.count >= 5) { [self.dataArray removeAllObjects]; [self.titles removeAllObjects]; for (int i = 0; i < 5; i++) { QXGiftScrollModel*md = list[i]; [self.dataArray addObject:md]; [self.titles addObject:md.fromUserName]; } }else{ for (QXGiftScrollModel*md in list) { [self.dataArray insertObject:md atIndex:0]; [self.titles insertObject:md.fromUserName atIndex:0]; } if (self.dataArray.count > 5) { [self.dataArray removeLastObject]; [self.titles removeLastObject]; } } self.cycleScrollView.imageURLStringsGroup = self.titles; } - (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view{ return [QXGiftScrollViewCell class]; } - (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view{ QXGiftScrollViewCell *myCell = (QXGiftScrollViewCell *)cell; myCell.model = self.dataArray[index]; } -(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickGiftScrollView:index:model:)]) { [self.delegate didClickGiftScrollView:self index:index model:self.dataArray[index]]; } } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } -(NSMutableArray *)titles{ if (!_titles) { _titles = [NSMutableArray array]; } return _titles; } @end @implementation QXGiftScrollViewCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; } return self; } - (void)setModel:(QXGiftScrollModel *)model{ _model = model; NSString *giftInfo = [NSString stringWithFormat:@"%@%@%@ %@X%@",model.fromUserName,QXText(@"送给了"),model.toUserName,model.giftName,model.number]; NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:giftInfo]; [attr yy_setColor:RGB16A(0xffffff, 0.84) range:[giftInfo rangeOfString:QXText(@"送给了")]]; self.titleLabel.attributedText = attr; } -(void)initSubViews{ self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_gift_bg"]]; [self.contentView addSubview:self.bgImageView]; [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.left.top.bottom.equalTo(self); }]; self.gotoRoomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_goto_room"]]; self.gotoRoomImageView.contentMode = UIViewContentModeScaleAspectFit; [self.contentView addSubview:self.gotoRoomImageView]; [self.gotoRoomImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-ScaleWidth(25)); make.centerY.equalTo(self); make.width.mas_equalTo(ScaleWidth(50)); make.height.mas_equalTo(ScaleWidth(20)); }]; // self.noticeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_notice"]]; // [self.contentView addSubview:self.noticeImageView]; // [self.noticeImageView mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.equalTo(self).offset(12); // make.centerY.equalTo(self); // make.size.mas_equalTo(CGSizeMake(24, 24)); // }]; self.titleLabel = [[MarqueeLabel alloc] initWithFrame:CGRectZero]; self.titleLabel.scrollDuration = 2; self.titleLabel.marqueeType = MLLeftRight; self.titleLabel.textColor = QXConfig.themeColor; self.titleLabel.font = [UIFont systemFontOfSize:14]; [self.contentView addSubview:self.titleLabel]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.equalTo(self); make.left.mas_equalTo(ScaleWidth(52)); make.right.equalTo(self.gotoRoomImageView.mas_left).offset(-8); }]; } @end @implementation QXGiftScrollModel @end