Files
yinmeng-ios/xplan-ios/Main/Room/View/AnimationView/XPRoomYearActivityView.m
2022-11-26 19:24:46 +08:00

215 lines
6.8 KiB
Objective-C

//
// XPRoomYearActivityView.m
// xplan-ios
//
// Created by GLEN on 2022/11/26.
//
#import "XPRoomYearActivityView.h"
///Third
#import <Masonry/Masonry.h>
///Tool
#import "ThemeColor+Room.h"
#import "ThemeColor.h"
#import "XPMacro.h"
///Model
#import "RoomHalfHourRankModel.h"
///View
#import "NetImageView.h"
@interface XPRoomYearActivityView()
///背景
@property (nonatomic,strong) UIImageView *bgImageView;
///icon
@property (nonatomic,strong) NetImageView *sendAvatar;
///头像
@property (nonatomic,strong) NetImageView *receiveAvatar;
///恭喜
@property (nonatomic,strong) UILabel *sendNick;
///昵称
@property (nonatomic,strong) UILabel *receiveNick;
///描述
@property (nonatomic, strong) UILabel *descLabel;
///数量
@property (nonatomic,strong) UILabel *countLabel;
///排行
@property (nonatomic, strong) UIButton *gotoButton;
@end
@implementation XPRoomYearActivityView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.bgImageView];
[self addSubview:self.sendNick];
[self addSubview:self.sendAvatar];
[self addSubview:self.descLabel];
[self addSubview:self.receiveNick];
[self addSubview:self.receiveAvatar];
[self addSubview:self.countLabel];
[self addSubview:self.gotoButton];
}
- (void)initSubViewConstraints {
[self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
}];
[self.sendNick mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(35*KScreenWidth/375);
make.centerY.mas_equalTo(self.bgImageView);
}];
[self.sendAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.sendNick.mas_right).mas_offset(3);
make.centerY.mas_equalTo(self);
make.width.height.mas_equalTo(20);
}];
[self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.sendAvatar.mas_right).mas_offset(3);
make.centerY.mas_equalTo(self);
}];
[self.receiveNick mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.descLabel.mas_right).mas_offset(3);
make.centerY.mas_equalTo(self);
}];
[self.receiveAvatar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.receiveNick.mas_right).mas_offset(3);
make.centerY.mas_equalTo(self);
make.width.height.mas_equalTo(20);
}];
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.receiveAvatar.mas_right).mas_offset(3);
make.centerY.mas_equalTo(self);
}];
[self.gotoButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-31*KScreenWidth / 375);
make.centerY.mas_equalTo(self);
make.size.mas_equalTo(CGSizeMake(40, 18));
}];
}
- (void)setModel:(XPRoomGiftBroadCastModel *)model {
_model = model;
if (model) {
self.receiveAvatar.imageUrl = model.recvUserAvatar;
self.sendAvatar.imageUrl = model.sendUserAvatar;
if (model.recvUserNick.length > 4) {
model.recvUserNick = [model.recvUserNick substringToIndex:4];
}
if (model.sendUserNick.length > 4) {
model.sendUserNick = [model.sendUserNick substringToIndex:4];
}
if (model.giftName.length > 6) {
model.giftName = [model.giftName substringToIndex:6];
}
self.sendNick.text = model.sendUserNick;
self.receiveNick.text = model.recvUserNick;
self.countLabel.text = [NSString stringWithFormat:@"%@ x%ld", model.giftName, model.giftNum];
}
}
- (void)onGotoButtonClick:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPRoomYearActivityViewEnterRoom:)]) {
[self.delegate xPRoomYearActivityViewEnterRoom:[NSString stringWithFormat:@"%ld", self.model.roomUid]];
}
}
#pragma mark - Getters And Setters
- (UIImageView *)bgImageView {
if (!_bgImageView) {
_bgImageView = [[UIImageView alloc] init];
_bgImageView.image = [UIImage imageNamed:@"YearActivity_bg"];
_bgImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _bgImageView;
}
- (NetImageView *)sendAvatar {
if (!_sendAvatar) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
_sendAvatar = [[NetImageView alloc] initWithConfig:config];
_sendAvatar.layer.masksToBounds = YES;
_sendAvatar.layer.cornerRadius = 10;
_sendAvatar.layer.borderColor = UIColorFromRGB(0xFBC200).CGColor;
_sendAvatar.layer.borderWidth = 1;
}
return _sendAvatar;
}
- (UILabel *)sendNick {
if (!_sendNick) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12];
label.textColor = UIColorFromRGB(0xFBC200);
_sendNick = label;
}
return _sendNick;
}
- (NetImageView *)receiveAvatar {
if (!_receiveAvatar) {
NetImageConfig * config = [[NetImageConfig alloc]init];
config.imageType = ImageTypeUserIcon;
_receiveAvatar = [[NetImageView alloc] initWithConfig:config];
_receiveAvatar.layer.masksToBounds = YES;
_receiveAvatar.layer.cornerRadius = 10;
_receiveAvatar.layer.borderColor = UIColorFromRGB(0xFBC200).CGColor;
_receiveAvatar.layer.borderWidth = 1;
}
return _receiveAvatar;
}
- (UILabel *)receiveNick {
if (!_receiveNick) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12];
label.textColor = UIColorFromRGB(0xFBC200);
_receiveNick = label;
}
return _receiveNick;
}
- (UILabel *)descLabel {
if (!_descLabel) {
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12];
label.textColor = [UIColor whiteColor];
label.text = @"送给";
_descLabel = label;
}
return _descLabel;
}
- (UILabel *)countLabel {
if (!_countLabel) {
_countLabel = [[UILabel alloc] init];
_countLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
_countLabel.textColor = UIColorFromRGB(0x80F9FF);
}
return _countLabel;
}
- (UIButton *)gotoButton {
if (!_gotoButton) {
_gotoButton = [[UIButton alloc] init];
[_gotoButton setBackgroundImage:[UIImage imageNamed:@"YearActivity_goto"] forState:UIControlStateNormal];
[_gotoButton addTarget:self action:@selector(onGotoButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _gotoButton;
}
@end