| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- //
- // MOActivityRewardView.m
- // MiMoLive
- //
- // Created by MiMo on 2025/5/23.
- //
- #import "MOActivityRewardView.h"
- @interface MOActivityRewarItemView ()
- @property (nonatomic, strong) UIImageView *iconImgView;
- @property (nonatomic, strong) UIImageView *coverImgView;
- @property (nonatomic, strong) UILabel *amountLabel;
- @property (nonatomic, strong) UILabel *nameLabel;
- @end
- @implementation MOActivityRewarItemView
- - (instancetype)init {
- if (self = [super init]) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupImageUrl:(NSString *)imageUrl amountText:(NSString *)amountText bgUrl:(NSString *)bgUrl nameText:(NSString *)nameText iconTextColor:(NSString *)iconTextColor {
- [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];
- [self.coverImgView sd_setImageWithURL:[NSURL URLWithString:bgUrl]];
- self.amountLabel.text = amountText;
- self.nameLabel.text = nameText;
-
- if (iconTextColor.length > 0) {
- NSString *colorString = [NSString stringWithFormat:@"#%@", iconTextColor];
- UIColor *textColor = [MOTools colorWithHexString:colorString];
- self.amountLabel.textColor = textColor;
- self.nameLabel.textColor = textColor;
- }
- }
- - (void)setupUI {
- [self addSubview:self.coverImgView];
- [self.coverImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0);
- make.centerX.mas_equalTo(0);
- make.width.mas_equalTo(kScaleWidth(66));
- make.height.mas_equalTo(kScaleWidth(66));
- }];
-
- [self addSubview:self.iconImgView];
- [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.coverImgView);
- make.width.mas_equalTo(kScaleWidth(52));
- make.height.mas_equalTo(kScaleWidth(52));
- }];
-
- [self addSubview:self.amountLabel];
- [self.amountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.coverImgView.mas_bottom).offset(2);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(18);
- }];
-
- [self addSubview:self.nameLabel];
- [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.amountLabel.mas_bottom);
- make.left.right.mas_equalTo(0);
- make.height.mas_equalTo(20);
- }];
-
- }
- - (UIImageView *)iconImgView {
- if (!_iconImgView) {
- _iconImgView = [[UIImageView alloc] init];
- _iconImgView.contentMode = UIViewContentModeScaleAspectFit;
- _iconImgView.clipsToBounds = YES;
- }
- return _iconImgView;
- }
- - (UIImageView *)coverImgView {
- if (!_coverImgView) {
- _coverImgView = [[UIImageView alloc] init];
- _coverImgView.contentMode = UIViewContentModeScaleAspectFill;
- }
- return _coverImgView;
- }
- - (UILabel *)amountLabel {
- if (!_amountLabel) {
- _amountLabel = [[UILabel alloc] init];
- _amountLabel.font = [MOTextTools getTheFontWithSize:14.0 AndFontName:kNormalContentBlodFontStr];
- _amountLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
- _amountLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _amountLabel;
- }
- - (UILabel *)nameLabel {
- if (!_nameLabel) {
- _nameLabel = [[UILabel alloc] init];
- _nameLabel.font = [UIFont systemFontOfSize:12];
- _nameLabel.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
- _nameLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _nameLabel;
- }
- @end
- #define kMOActivityRewardViewWidth kScaleWidth(297)
- #define kMOActivityRewardViewHeight kScaleWidth(384)
- #import "MOActivityRewardView.h"
- @interface MOActivityRewardView ()
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UIImageView *bgImgView;
- @property (nonatomic, strong) UIStackView *awardStackkView;
- @property (nonatomic, strong) UIScrollView *scrollView;
- @property (nonatomic, strong) UIButton *okButton;
- @property (nonatomic, strong) UIButton *closeButton;
- @end
- @implementation MOActivityRewardView
- - (instancetype)init {
- if (self = [super init]) {
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI {
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.mas_equalTo(0);
- }];
-
- [self addSubview:self.bgImgView];
- [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(0);
- make.centerY.mas_equalTo(-35);
- make.size.mas_equalTo(CGSizeMake(kMOActivityRewardViewWidth, kMOActivityRewardViewHeight));
- }];
-
- [self.bgImgView addSubview:self.scrollView];
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgImgView.mas_top).offset(kMOActivityRewardViewHeight * 0.6);
- make.centerX.mas_equalTo(0);
- make.height.mas_equalTo(kScaleWidth(66) + 40);
- make.width.mas_equalTo(kScaleWidth(66) * 3 + 40);
- }];
-
- [self.scrollView addSubview:self.awardStackkView];
- [self.awardStackkView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.scrollView);
- }];
-
- [self.bgImgView addSubview:self.okButton];
- [self.okButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.mas_equalTo(0);
- make.height.mas_equalTo(80);
- }];
-
- [self addSubview:self.closeButton];
- [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.bgImgView.mas_bottom).offset(40);
- make.centerX.mas_equalTo(0);
- make.size.mas_equalTo(CGSizeMake(30, 30));
- }];
- }
- - (void)setModel:(MORtmUserDialog *)model {
- _model = model;
-
- [self.bgImgView sd_setImageWithURL:[NSURL URLWithString:model.backgroundImg]];
-
- if (model.iconItems.count == 0) {
- self.scrollView.hidden = YES;
- return;
- }
-
- [self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgImgView.mas_top).offset(kMOActivityRewardViewHeight * model.giftTopNum);
- }];
-
- [model.iconItems enumerateObjectsUsingBlock:^(MORtmUserDialogItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- MOActivityRewarItemView *item = [[MOActivityRewarItemView alloc] init];
- if (obj.type == 1) {//钻石
- NSString *amountText = [NSString stringWithFormat:@"* %zd", obj.amount];
- [item setupImageUrl:obj.img amountText:amountText bgUrl:model.iconBackgroundImg nameText:@"" iconTextColor:model.iconTextColor];
- } else if (obj.type == 2) {//道具
- NSString *amountText = [NSString stringWithFormat:@"* %zdd", obj.amount];
- [item setupImageUrl:obj.img amountText:amountText bgUrl:model.iconBackgroundImg nameText:obj.name iconTextColor:model.iconTextColor];
- } else if (obj.type == 3) {//礼物
- NSString *amountText = [NSString stringWithFormat:@"* %zd", obj.amount];
- [item setupImageUrl:obj.img amountText:amountText bgUrl:model.iconBackgroundImg nameText:obj.name iconTextColor:model.iconTextColor];
- }
-
- [self.awardStackkView addArrangedSubview:item];
- [item mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(kScaleWidth(66));
- make.height.mas_equalTo(kScaleWidth(66) + 40);
- }];
- }];
-
- if (model.iconItems.count <= 3) {
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(kScaleWidth(66) * model.iconItems.count + (15 * (model.iconItems.count - 1)));
- }];
- [self.awardStackkView setNeedsLayout];
- [self.awardStackkView layoutIfNeeded];
- } else if (model.iconItems.count > 3) {
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.bgImgView.mas_top).offset(kMOActivityRewardViewHeight * 0.6);
- make.left.mas_equalTo(25);
- make.right.mas_equalTo(-15);
- make.height.mas_equalTo(kScaleWidth(66) + 40);
- }];
- [self.awardStackkView setNeedsLayout];
- [self.awardStackkView layoutIfNeeded];
- }
- self.scrollView.scrollEnabled = (self.model.iconItems.count > 3);
-
- }
- - (void)okBtnAction {
- [self dismiss];
- }
- - (void)show {
- UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
- [keyWindow addSubview:self];
- self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
-
- //动画效果
- self.bgImgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
- self.bgImgView.alpha = 0;
- [UIView animateWithDuration:0.2 animations:^ {
- self.bgImgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
- self.bgImgView.alpha = 1;
- } completion:nil];
- }
- - (void)dismiss {
- [UIView animateWithDuration:0.2 animations:^ {
- self.bgImgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
- self.bgImgView.alpha = 0;
- } completion:^(BOOL finished) {
- if (finished) {
- [self removeFromSuperview];
- }
- }];
- }
- - (UIView *)bgView {
- if (!_bgView) {
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [MOTools colorWithHexString:@"#000000" alpha:0.5];
- // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
- // [_bgView addGestureRecognizer:tap];
- }
- return _bgView;
- }
- - (UIImageView *)bgImgView {
- if (!_bgImgView) {
- _bgImgView = [[UIImageView alloc] init];
- _bgImgView.contentMode = UIViewContentModeScaleAspectFill;
- _bgImgView.userInteractionEnabled = YES;
- }
- return _bgImgView;
- }
- - (UIStackView *)awardStackkView {
- if (!_awardStackkView) {
- _awardStackkView = [[UIStackView alloc] init];
- _awardStackkView.axis = UILayoutConstraintAxisHorizontal;
- _awardStackkView.distribution = UIStackViewDistributionFillEqually;
- _awardStackkView.spacing = 15.0;
- }
- return _awardStackkView;
- }
- - (UIScrollView *)scrollView {
- if (!_scrollView) {
- _scrollView = [[UIScrollView alloc] init];
- _scrollView.showsVerticalScrollIndicator = NO;
- _scrollView.showsHorizontalScrollIndicator = NO;
- _scrollView.alwaysBounceVertical = NO;
- _scrollView.alwaysBounceHorizontal = YES;
- _scrollView.directionalLockEnabled = YES;
- }
- return _scrollView;
- }
- - (UIButton *)okButton {
- if (!_okButton) {
- _okButton = [[UIButton alloc] init];
- _okButton.backgroundColor = [UIColor clearColor];
- [_okButton addTarget:self action:@selector(okBtnAction) forControlEvents:UIControlEventTouchUpInside];
- }
- return _okButton;
- }
- - (UIButton *)closeButton {
- if (!_closeButton) {
- _closeButton = [[UIButton alloc] init];
- [_closeButton setImage:[UIImage imageNamed:@"icon_activity_reward_close"] forState:UIControlStateNormal];
- [_closeButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeButton;
- }
- @end
|