// // XPGiftLuckyGiftBoradCastView.m // xplan-ios // // Created by GreenLand on 2022/10/8. // #import "XPGiftLuckyGiftBroadcastView.h" ///Third #import #import #import ///Tool #import "ThemeColor.h" #import "NSArray+Safe.h" ///Model #import "GiftLuckyBroadcastModel.h" @interface XPGiftLuckyGiftBroadcastCell : UICollectionViewCell @property (nonatomic,strong) YYLabel *titleLabel; @property (nonatomic,strong) GiftLuckyBroadcastModel *giftInfo; @end @implementation XPGiftLuckyGiftBroadcastCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { [self.contentView addSubview:self.titleLabel]; } - (void)initSubViewConstraints { [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.contentView); }]; } - (NSMutableAttributedString *)createTextAttribute:(NSString *)text color:(UIColor *)color { if (text == nil || text.length <= 0) { text = @""; } NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:text attributes:nil]; attribute.yy_font = [UIFont systemFontOfSize:12]; attribute.yy_color = color; return attribute; } #pragma mark - Getters And Setters - (void)setGiftInfo:(GiftLuckyBroadcastModel *)giftInfo { _giftInfo = giftInfo; if (_giftInfo) { NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init]; [attribute appendAttributedString:[self createTextAttribute:@"恭喜 " color:[UIColor whiteColor]]]; NSString * nick = _giftInfo.nick; if (nick.length > 6) { nick = [nick substringToIndex:6]; } [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%@ " , nick] color:[ThemeColor colorWithHexString:@"#FFD436"]]]; [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"开出%@获得 ", giftInfo.luckyBagName] color:[UIColor whiteColor]]]; [attribute appendAttributedString:[self createTextAttribute:[NSString stringWithFormat:@"%@ " , _giftInfo.giftName] color:[ThemeColor colorWithHexString:@"#6FE3FF"]]]; self.titleLabel.attributedText = attribute; } } - (YYLabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[YYLabel alloc] init]; } return _titleLabel; } @end @interface XPGiftLuckyGiftBroadcastView() ///背景 @property (nonatomic, strong) UIImageView *bgImageView; ///玩法说明 @property (nonatomic, strong) UIImageView *playImageView; ///icon @property (nonatomic, strong) UIImageView *iconImageView; ///文字轮播 @property (nonatomic, strong) SDCycleScrollView *cycleScrollView; @end @implementation XPGiftLuckyGiftBroadcastView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubViews]; [self initSubViewConstraints]; } return self; } #pragma mark - Private Method - (void)initSubViews { [self addSubview:self.bgImageView]; [self addSubview:self.iconImageView]; [self addSubview:self.playImageView]; [self addSubview:self.cycleScrollView]; } - (void)initSubViewConstraints { [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.right.mas_equalTo(self).inset(10); make.height.mas_equalTo(40); }]; [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.bgImageView); make.left.mas_equalTo(self.bgImageView).mas_offset(8); make.width.height.mas_equalTo(20); }]; [self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.iconImageView.mas_right); make.right.mas_equalTo(self.playImageView.mas_left).offset(-5); make.top.bottom.mas_equalTo(self.bgImageView); }]; [self.playImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.right.bottom.mas_equalTo(self.bgImageView); make.width.mas_equalTo(67); }]; } #pragma mark - action - (void)playButtonAction:(UITapGestureRecognizer *)tap { if (self.delegate && [self.delegate respondsToSelector:@selector(xPGiftLuckyGiftBroadcastViewPlayDescClick)]) { [self.delegate xPGiftLuckyGiftBroadcastViewPlayDescClick]; } } #pragma mark - SDCycleScrollViewDelegate - (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view { return XPGiftLuckyGiftBroadcastCell.class; } - (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view { XPGiftLuckyGiftBroadcastCell *myCell = (XPGiftLuckyGiftBroadcastCell *)cell; GiftLuckyBroadcastModel * info = [self.records safeObjectAtIndex1:index]; myCell.giftInfo = info; } #pragma mark - Getters And Setters - (void)setRecords:(NSArray *)records { _records = records; if (_records.count > 0) { NSMutableArray * array = [NSMutableArray array]; for (GiftLuckyBroadcastModel * item in _records) { [array addObject:item.giftName]; } if (array.count > 0) { self.cycleScrollView.imageURLStringsGroup = array; [self.cycleScrollView autoScroll]; } } } - (UIImageView *)bgImageView { if (!_bgImageView) { _bgImageView = [[UIImageView alloc] init]; _bgImageView.image = [UIImage imageNamed:@"gift_lucky_broadcast_bg"]; _bgImageView.contentMode = UIViewContentModeScaleToFill; } return _bgImageView; } - (UIImageView *)iconImageView { if (!_iconImageView) { _iconImageView = [[UIImageView alloc] init]; _iconImageView.image = [UIImage imageNamed:@"gift_lucky_broadcast_icon"]; } return _iconImageView; } - (UIImageView *)playImageView { if (!_playImageView) { _playImageView = [[UIImageView alloc] init]; _playImageView.image = [UIImage imageNamed:@"gift_lucky_broadcast_playType"]; _playImageView.contentMode = UIViewContentModeScaleToFill; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(playButtonAction:)]; _playImageView.userInteractionEnabled = YES; [_playImageView addGestureRecognizer:tap]; } return _playImageView; } - (SDCycleScrollView *)cycleScrollView { if (!_cycleScrollView) { _cycleScrollView = [[SDCycleScrollView alloc] init]; _cycleScrollView.backgroundColor = [UIColor clearColor]; _cycleScrollView.layer.masksToBounds = YES; _cycleScrollView.delegate = self; _cycleScrollView.showPageControl = NO; _cycleScrollView.autoScrollTimeInterval = 3.0; [_cycleScrollView disableScrollGesture]; } return _cycleScrollView; } @end