增加换肤功能
This commit is contained in:
124
QXLive/HomePage(声播)/View/首页/QXGiftScrollView.m
Normal file
124
QXLive/HomePage(声播)/View/首页/QXGiftScrollView.m
Normal file
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// QXGiftScrollView.m
|
||||
// QXLive
|
||||
//
|
||||
// Created by 启星 on 2025/5/13.
|
||||
//
|
||||
|
||||
#import "QXGiftScrollView.h"
|
||||
#import <SDCycleScrollView/SDCycleScrollView.h>
|
||||
static NSInteger maxCount = 5;
|
||||
@interface QXGiftScrollView()<SDCycleScrollViewDelegate>
|
||||
@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.cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.bounds delegate:self placeholderImage:nil];
|
||||
self.cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
|
||||
self.cycleScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
|
||||
self.cycleScrollView.delegate = self;
|
||||
[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;
|
||||
}
|
||||
- (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;
|
||||
self.titleLabel.text = [NSString stringWithFormat:@"%@%@%@ %@X%@",model.fromUserName,QXText(@"送给了"),model.toUserName,model.giftName,model.number];
|
||||
}
|
||||
-(void)initSubViews{
|
||||
|
||||
self.gotoRoomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home_goto_room"]];
|
||||
[self.contentView addSubview:self.gotoRoomImageView];
|
||||
[self.gotoRoomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.top.bottom.equalTo(self);
|
||||
make.width.mas_equalTo(85);
|
||||
}];
|
||||
|
||||
|
||||
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.textColor;
|
||||
self.titleLabel.font = [UIFont systemFontOfSize:14];
|
||||
[self.contentView addSubview:self.titleLabel];
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.bottom.equalTo(self);
|
||||
make.left.equalTo(self.noticeImageView.mas_right).offset(8);
|
||||
make.right.equalTo(self.gotoRoomImageView.mas_left).offset(-8);
|
||||
}];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation QXGiftScrollModel
|
||||
|
||||
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user