Files
peko-ios/YuMi/Modules/YMRoom/View/AnimationView/XPRoomStarKitchenBannerView.m
2024-03-12 18:17:33 +08:00

139 lines
5.0 KiB
Objective-C

//
// XPRoomStarKitchenBannerView.m
// YuMi
//
// Created by YuMi on 2022/12/7.
//
#import <SVGA.h>
#import "XPRoomStarKitchenBannerView.h"
///Third
#import <Masonry/Masonry.h>
#import "YUMIMacroUitls.h"
#import "DJDKMIMOMColor.h"
@interface XPRoomStarKitchenBannerView()
@property (strong, nonatomic) SVGAParser *parser;
@property (nonatomic,strong) SVGAImageView *svgaView;
@property (nonatomic,strong) UIImageView *bgImageView;
@property (nonatomic,strong) UILabel *titleView;
@property (nonatomic,strong) UIButton *clickBtn;
@end
@implementation XPRoomStarKitchenBannerView
-(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.svgaView];
[self addSubview:self.titleView];
[self addSubview:self.clickBtn];
}
- (void)initSubViewConstraints {
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.svgaView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
[self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(21));
make.left.mas_equalTo(kGetScaleWidth(85));
make.bottom.equalTo(self.mas_bottom).mas_offset(-kGetScaleWidth(13.5));
make.right.mas_equalTo(-kGetScaleWidth(53.5));
}];
[self.clickBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
-(void)setStarModel:(XPRoomStarKitchenModel *)starModel{
_starModel = starModel;
NSString *name = _starModel.nick.length < 7 ? _starModel.nick : [NSString stringWithFormat:@"%@...",[_starModel.nick substringWithRange:NSMakeRange(0, 6)]];
NSString *title = [NSString stringWithFormat:YMLocalizedString(@"XPRoomStarKitchenBannerView0"),name,_starModel.itemMultiple,_starModel.diamonds];
[self.titleView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(kGetScaleWidth(_isSvga == YES && KScreenWidth == 320 ? 18 : 21));
}];
NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithString:title attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:10],NSForegroundColorAttributeName:[UIColor whiteColor]}];
[att addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFEF23E)} range:[title rangeOfString:name]];
[att addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x00EAFF)} range:[title rangeOfString:[NSString stringWithFormat:@" %@",_starModel.itemMultiple]]];
[att addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x00EAFF)} range:[title rangeOfString:[NSString stringWithFormat:@" %@",_starModel.diamonds]]];
if(_isSvga == YES){
self.bgImageView.hidden = YES;
self.svgaView.hidden = NO;
self.titleView.hidden = NO;
self.titleView.attributedText = att;
@kWeakify(self);
[self.parser parseWithNamed:@"pi_crazy_zoo" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
@kStrongify(self);
self.svgaView.loops = 1;
self.svgaView.clearsAfterStop = NO;
self.svgaView.videoItem = videoItem;
// [self.svgaView setAttributedText:att forKey:@"noble_text_tx"];
[self.svgaView startAnimation];
} failureBlock:^(NSError * _Nonnull error) {
}];
}else{
self.bgImageView.hidden = NO;
self.titleView.hidden = NO;
self.svgaView.hidden = YES;
self.titleView.attributedText = att;
}
}
-(void)clickAction{
if(self.delegate && [self.delegate respondsToSelector:@selector(xPRoomStarKitchenBannerView:didClick:)]){
[self.delegate xPRoomStarKitchenBannerView:self didClick:self.starModel];
}
}
#pragma mark -懒加载
- (UIImageView *)bgImageView{
if (!_bgImageView){
_bgImageView = [UIImageView new];
_bgImageView.image = [UIImage imageNamed:@"room_star_kitchen"];
_bgImageView.userInteractionEnabled = YES;
}
return _bgImageView;
}
-(UILabel *)titleView{
if (!_titleView){
_titleView = [UILabel new];
_titleView.textAlignment = NSTextAlignmentCenter;
_titleView.numberOfLines = 2;
}
return _titleView;
}
- (SVGAParser *)parser {
if (!_parser) {
_parser = [[SVGAParser alloc]init];
}
return _parser;
}
- (SVGAImageView *)svgaView {
if (!_svgaView) {
_svgaView= [[SVGAImageView alloc]init];
_svgaView.backgroundColor = [UIColor clearColor];
_svgaView.userInteractionEnabled = YES;
}
return _svgaView;
}
-(UIButton *)clickBtn{
if (!_clickBtn){
_clickBtn = [UIButton new];
[_clickBtn addTarget:self action:@selector(clickAction) forControlEvents:UIControlEventTouchUpInside];
}
return _clickBtn;
}
@end