113 lines
3.7 KiB
Objective-C
113 lines
3.7 KiB
Objective-C
//
|
|
// XPRoomGiftCompoundView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by GreenLand on 2022/8/5.
|
|
//
|
|
|
|
#import "XPRoomGiftCompoundView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <SVGA.h>
|
|
#import "XPMacro.h"
|
|
#import "ThemeColor+Room.h"
|
|
#import "XPGiftCompoundModel.h"
|
|
#import "NSObject+MJExtension.h"
|
|
|
|
@interface XPRoomGiftCompoundView ()
|
|
|
|
///动画管理类
|
|
@property (strong, nonatomic) SVGAParser *parser;
|
|
///礼物合成特效
|
|
@property (nonatomic,strong) SVGAImageView *compoundGiftView;
|
|
///显示文本内容
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
|
|
@end
|
|
|
|
@implementation XPRoomGiftCompoundView
|
|
|
|
- (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.compoundGiftView];
|
|
[self addSubview:self.titleLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.compoundGiftView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.mas_equalTo(self);
|
|
make.height.mas_equalTo(45);
|
|
}];
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.compoundGiftView);
|
|
}];
|
|
}
|
|
|
|
- (NSAttributedString *)createAttribute:(NSString * )text color:(UIColor *)color fontSize:(CGFloat)fonSize {
|
|
NSDictionary * attribute = @{NSFontAttributeName:[UIFont systemFontOfSize:fonSize], NSForegroundColorAttributeName:color};
|
|
NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:text attributes:attribute];
|
|
return attr;
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setCompoundGiftInfo:(NSDictionary *)compoundGiftInfo {
|
|
if (compoundGiftInfo) {
|
|
XPGiftCompoundModel * giftInfo = [XPGiftCompoundModel modelWithDictionary:compoundGiftInfo];
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] init];
|
|
CGFloat fontSize = 22;
|
|
NSString *nickStr = giftInfo.nick;
|
|
if (nickStr.length > 6) {
|
|
nickStr = [NSString stringWithFormat:@"%@…", [giftInfo.nick substringToIndex:6]];
|
|
}
|
|
[attribute appendAttributedString:[self createAttribute:@"恭喜" color:[UIColor whiteColor] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:nickStr color:[ThemeColor messageNickColor] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:giftInfo.msg color:[UIColor whiteColor] fontSize:fontSize]];
|
|
[attribute appendAttributedString:[self createAttribute:giftInfo.giftName color:[ThemeColor messageNickColor] fontSize:fontSize]];
|
|
|
|
@kWeakify(self);
|
|
[self.parser parseWithNamed:@"compound_gift_banner" inBundle:[NSBundle mainBundle] completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
|
|
@kStrongify(self);
|
|
self.compoundGiftView.loops = 1;
|
|
self.compoundGiftView.clearsAfterStop = NO;
|
|
self.compoundGiftView.videoItem = videoItem;
|
|
[self.compoundGiftView setAttributedText:attribute forKey:@"noble_text_tx"];
|
|
[self.compoundGiftView startAnimation];
|
|
} failureBlock:^(NSError * _Nonnull error) {
|
|
|
|
}];
|
|
}
|
|
}
|
|
|
|
- (SVGAImageView *)compoundGiftView {
|
|
if (!_compoundGiftView) {
|
|
_compoundGiftView = [[SVGAImageView alloc]init];
|
|
_compoundGiftView.backgroundColor = [UIColor clearColor];
|
|
_compoundGiftView.userInteractionEnabled = NO;
|
|
}
|
|
return _compoundGiftView;
|
|
}
|
|
|
|
- (SVGAParser *)parser {
|
|
if (!_parser) {
|
|
_parser = [[SVGAParser alloc]init];
|
|
}
|
|
return _parser;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
@end
|