153 lines
5.6 KiB
Objective-C
153 lines
5.6 KiB
Objective-C
//
|
|
// XPRoomCandyGiftView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2021/12/10.
|
|
//
|
|
|
|
#import "XPRoomCandyGiftView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <SVGA.h>
|
|
#import "ThemeColor+Room.h"
|
|
#import "CandyTreeResultModel.h"
|
|
#import "NSObject+MJExtension.h"
|
|
|
|
|
|
@interface XPRoomCandyGiftView ()
|
|
///动画管理类
|
|
@property (strong, nonatomic) SVGAParser *parser;
|
|
///糖果树特效
|
|
@property (nonatomic,strong) SVGAImageView *candyTreeView;
|
|
///背景图
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
///显示文本内容
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
@end
|
|
|
|
@implementation XPRoomCandyGiftView
|
|
|
|
- (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.candyTreeView];
|
|
[self addSubview:self.backImageView];
|
|
[self addSubview:self.titleLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.candyTreeView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.top.mas_equalTo(self);
|
|
make.height.mas_equalTo(kGetScaleWidth(55));
|
|
}];
|
|
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.top.mas_equalTo(self.candyTreeView);
|
|
make.height.mas_equalTo(kGetScaleWidth(55));
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.bottom.equalTo(self.backImageView);
|
|
make.leading.mas_equalTo(kGetScaleWidth(84));
|
|
make.trailing.mas_equalTo(-kGetScaleWidth(70.5));
|
|
|
|
}];
|
|
}
|
|
|
|
- (NSAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color fontSize:(CGFloat)fonSize {
|
|
if(text.length == 0)return nil;
|
|
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:fonSize], NSForegroundColorAttributeName:color};
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
|
|
return attr;
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setCandyInfo:(NSDictionary *)candyInfo {
|
|
if (candyInfo) {
|
|
CandyTreeGiftInfoModel * giftInfo = [CandyTreeGiftInfoModel modelWithDictionary:candyInfo];
|
|
if(giftInfo.nick.length > 8){
|
|
giftInfo.nick = [NSString stringWithFormat:@"%@...",[giftInfo.nick substringToIndex:8]];
|
|
}
|
|
NSString *text = [NSString stringWithFormat:YMLocalizedString(@"XPRoomCandyGiftView0"),giftInfo.nick,giftInfo.prizeName,[NSString stringWithFormat:@" X %d", giftInfo.prizeNum]];
|
|
CGFloat fontSize = self.isMaxLargeGift ? 12 : 12;
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithAttributedString:[self createAttribute:text color:[UIColor whiteColor] fontSize:fontSize]];
|
|
|
|
[attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:UIColorFromRGB(0xFFE44E)} range:[text rangeOfString:giftInfo.nick]];
|
|
|
|
[attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:UIColorFromRGB(0xFFE44E)} range:[text rangeOfString:giftInfo.prizeName]];
|
|
|
|
if (giftInfo.prizeNum > 1) {
|
|
[attribute addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:[UIColor whiteColor]} range:[text rangeOfString:[NSString stringWithFormat:@" X %d", giftInfo.prizeNum]]];
|
|
}
|
|
self.titleLabel.attributedText = attribute;
|
|
self.titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
if (self.isMaxLargeGift) {
|
|
// self.backImageView.hidden = YES;
|
|
// self.candyTreeView.hidden = NO;
|
|
// @kWeakify(self);
|
|
//
|
|
// [self.parser parseWithNamed:@"pi_room_game_fine_love" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
// @kStrongify(self);
|
|
// self.candyTreeView.loops = 2;
|
|
// self.candyTreeView.clearsAfterStop = NO;
|
|
// self.candyTreeView.videoItem = videoItem;
|
|
// [self.candyTreeView startAnimation];
|
|
//
|
|
// } failureBlock:^(NSError * _Nonnull error) {
|
|
//
|
|
// }];
|
|
self.backImageView.image = [kImage(@"room_candytree_large_big_gift_bg") ms_SetImageForRTL];
|
|
self.backImageView.hidden = NO;
|
|
self.candyTreeView.hidden = YES;
|
|
} else {
|
|
self.backImageView.hidden = NO;
|
|
self.candyTreeView.hidden = YES;
|
|
self.backImageView.image = [kImage(@"room_candytree_large_gift_bg") ms_SetImageForRTL];
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
- (SVGAImageView *)candyTreeView {
|
|
if (!_candyTreeView) {
|
|
_candyTreeView = [[SVGAImageView alloc]init];
|
|
_candyTreeView.backgroundColor = [UIColor clearColor];
|
|
_candyTreeView.userInteractionEnabled = NO;
|
|
}
|
|
return _candyTreeView;
|
|
}
|
|
|
|
- (SVGAParser *)parser {
|
|
if (!_parser) {
|
|
_parser = [[SVGAParser alloc]init];
|
|
}
|
|
return _parser;
|
|
}
|
|
|
|
- (UIImageView *)backImageView {
|
|
if (!_backImageView) {
|
|
_backImageView = [[UIImageView alloc] init];
|
|
_backImageView.userInteractionEnabled = YES;
|
|
_backImageView.image = [UIImage imageNamed:@"room_candytree_large_gift_bg"];
|
|
}
|
|
return _backImageView;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
_titleLabel.numberOfLines = 2;
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
@end
|