271 lines
8.3 KiB
Objective-C
271 lines
8.3 KiB
Objective-C
//
|
|
// XPRoomTopRankView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by XY on 2023/3/15.
|
|
//
|
|
|
|
#import "XPRoomTopRankView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import "ThemeColor.h"
|
|
#import "NSArray+Safe.h"
|
|
///Tool
|
|
#import "NetImageView.h"
|
|
///Model
|
|
#import "XPRoomRankListModel.h"
|
|
|
|
@interface XPRoomTopRankView ()
|
|
|
|
///背景图
|
|
@property (nonatomic, strong) UIView *bgView;
|
|
|
|
/// 头像挂件
|
|
@property (nonatomic, strong) UIImageView *headwear1;
|
|
//@property (nonatomic, strong) UIImageView *headwear2;
|
|
//@property (nonatomic, strong) UIImageView *headwear3;
|
|
/// 头像
|
|
@property (nonatomic, strong) NetImageView *avatar1;
|
|
//@property (nonatomic, strong) NetImageView *avatar2;
|
|
//@property (nonatomic, strong) NetImageView *avatar3;
|
|
/// 贡献值
|
|
@property (nonatomic, strong) UILabel *value1;
|
|
//@property (nonatomic, strong) UILabel *value2;
|
|
//@property (nonatomic, strong) UILabel *value3;
|
|
|
|
@end
|
|
|
|
@implementation XPRoomTopRankView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self addSubview:self.bgView];
|
|
|
|
[self.bgView addSubview:self.headwear1];
|
|
// [self.bgView addSubview:self.headwear2];
|
|
// [self.bgView addSubview:self.headwear3];
|
|
|
|
[self.headwear1 addSubview:self.avatar1];
|
|
[self.headwear1 addSubview:self.value1];
|
|
|
|
// [self.headwear2 addSubview:self.avatar2];
|
|
// [self.headwear2 addSubview:self.value2];
|
|
//
|
|
// [self.headwear3 addSubview:self.avatar3];
|
|
// [self.headwear3 addSubview:self.value3];
|
|
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.bottom.right.left.mas_equalTo(0);
|
|
}];
|
|
|
|
[self.headwear1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(0);
|
|
make.left.mas_equalTo(0);
|
|
make.size.mas_equalTo(CGSizeMake(29, 33));
|
|
}];
|
|
[self.avatar1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
make.centerX.mas_equalTo(2.5);
|
|
make.centerY.mas_equalTo(4.5);
|
|
}];
|
|
[self.value1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.headwear1.mas_bottom);
|
|
make.centerX.mas_equalTo(3);
|
|
make.size.mas_equalTo(CGSizeMake(22, 8));
|
|
}];
|
|
|
|
// [self.headwear2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
// make.top.mas_equalTo(self.headwear1);
|
|
// make.left.mas_equalTo(self.headwear1.mas_right);
|
|
// make.size.mas_equalTo(self.headwear1);
|
|
// }];
|
|
// [self.avatar2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
// make.size.mas_equalTo(self.avatar1);
|
|
// make.centerX.mas_equalTo(2.5);
|
|
// make.centerY.mas_equalTo(4.5);
|
|
// }];
|
|
// [self.value2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
// make.centerY.mas_equalTo(self.headwear2.mas_bottom);
|
|
// make.centerX.mas_equalTo(3);
|
|
// make.size.mas_equalTo(self.value1);
|
|
// }];
|
|
//
|
|
// [self.headwear3 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
// make.top.mas_equalTo(self.headwear1);
|
|
// make.left.mas_equalTo(self.headwear2.mas_right);
|
|
// make.size.mas_equalTo(self.headwear1);
|
|
// }];
|
|
// [self.avatar3 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
// make.size.mas_equalTo(self.avatar1);
|
|
// make.centerX.mas_equalTo(2.5);
|
|
// make.centerY.mas_equalTo(4.5);
|
|
// }];
|
|
// [self.value3 mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
// make.centerY.mas_equalTo(self.headwear2.mas_bottom);
|
|
// make.centerX.mas_equalTo(3);
|
|
// make.size.mas_equalTo(self.value1);
|
|
// }];
|
|
|
|
}
|
|
|
|
/// 转化贡献值
|
|
- (NSString *)getAmountText:(NSInteger)amount {
|
|
if (amount >= 10000) {
|
|
return [NSString stringWithFormat:@"%.1fw",amount/10000.0];
|
|
}
|
|
return [NSString stringWithFormat:@"%ld",amount];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
- (void)setRankList:(NSArray *)rankList {
|
|
_rankList = rankList;
|
|
|
|
XPRoomRankListModel *model1 = [rankList safeObjectAtIndex1:0];
|
|
if (model1) {
|
|
self.avatar1.imageUrl = model1.avatar;
|
|
self.value1.text = [self getAmountText:model1.goldAmount];
|
|
}else{
|
|
self.avatar1.imageUrl = @"";
|
|
self.value1.text = @"0";
|
|
}
|
|
|
|
// XPRoomRankListModel *model2 = [rankList safeObjectAtIndex1:1];
|
|
// if (model2) {
|
|
// self.avatar2.imageUrl = model2.avatar;
|
|
// self.value2.text = [self getAmountText:model2.goldAmount];
|
|
// }else{
|
|
// self.avatar2.imageUrl = @"";
|
|
// self.value2.text = @"0";
|
|
// }
|
|
//
|
|
// XPRoomRankListModel *model3 = [rankList safeObjectAtIndex1:2];
|
|
// if (model3) {
|
|
// self.avatar3.imageUrl = model3.avatar;
|
|
// self.value3.text = [self getAmountText:model3.goldAmount];
|
|
// }else{
|
|
// self.avatar3.imageUrl = @"";
|
|
// self.value3.text = @"0";
|
|
// }
|
|
}
|
|
|
|
- (UIView *)bgView {
|
|
if (_bgView == nil) {
|
|
_bgView = [[UIView alloc] init];
|
|
}
|
|
return _bgView;
|
|
}
|
|
|
|
- (UIImageView *)headwear1 {
|
|
if (!_headwear1) {
|
|
_headwear1 = [[UIImageView alloc] init];
|
|
_headwear1.image = [UIImage imageNamed:@"room_rank_headwear_first"];
|
|
}
|
|
return _headwear1;
|
|
}
|
|
|
|
//- (UIImageView *)headwear2 {
|
|
// if (!_headwear2) {
|
|
// _headwear2 = [[UIImageView alloc] init];
|
|
// _headwear2.image = [UIImage imageNamed:@"room_rank_headwear_second"];
|
|
// }
|
|
// return _headwear2;
|
|
//}
|
|
//
|
|
//- (UIImageView *)headwear3 {
|
|
// if (!_headwear3) {
|
|
// _headwear3 = [[UIImageView alloc] init];
|
|
// _headwear3.image = [UIImage imageNamed:@"room_rank_headwear_third"];
|
|
// }
|
|
// return _headwear3;
|
|
//}
|
|
|
|
- (NetImageView *)avatar1 {
|
|
if (!_avatar1) {
|
|
NetImageConfig *config = [[NetImageConfig alloc] init];
|
|
config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
|
|
_avatar1 = [[NetImageView alloc] initWithConfig:config];
|
|
_avatar1.layer.cornerRadius = 11;
|
|
_avatar1.layer.masksToBounds = YES;
|
|
}
|
|
return _avatar1;
|
|
}
|
|
|
|
//- (NetImageView *)avatar2 {
|
|
// if (!_avatar2) {
|
|
// NetImageConfig *config = [[NetImageConfig alloc] init];
|
|
// config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
|
|
// _avatar2 = [[NetImageView alloc] initWithConfig:config];
|
|
// _avatar2.layer.cornerRadius = 11;
|
|
// _avatar2.layer.masksToBounds = YES;
|
|
// }
|
|
// return _avatar2;
|
|
//}
|
|
|
|
//- (NetImageView *)avatar3 {
|
|
// if (!_avatar3) {
|
|
// NetImageConfig *config = [[NetImageConfig alloc] init];
|
|
// config.placeHolder = [UIImageConstant defaultEmptyAvatarPlaceholder];
|
|
// _avatar3 = [[NetImageView alloc] initWithConfig:config];
|
|
// _avatar3.layer.cornerRadius = 11;
|
|
// _avatar3.layer.masksToBounds = YES;
|
|
// }
|
|
// return _avatar3;
|
|
//}
|
|
|
|
- (UILabel *)value1 {
|
|
if (!_value1) {
|
|
_value1 = [[UILabel alloc] init];
|
|
_value1.textColor = [ThemeColor colorWithHexString:@"#8E461A"];
|
|
_value1.textAlignment = NSTextAlignmentCenter;
|
|
_value1.text = @"0";
|
|
_value1.font = [UIFont systemFontOfSize:7 weight:UIFontWeightMedium];
|
|
_value1.backgroundColor = [ThemeColor colorWithHexString:@"#F5CD57"];
|
|
_value1.layer.cornerRadius = 4;
|
|
_value1.clipsToBounds = YES;
|
|
}
|
|
return _value1;
|
|
}
|
|
|
|
//- (UILabel *)value2 {
|
|
// if (!_value2) {
|
|
// _value2 = [[UILabel alloc] init];
|
|
// _value2.textColor = [ThemeColor colorWithHexString:@"#2E527A"];
|
|
// _value2.textAlignment = NSTextAlignmentCenter;
|
|
// _value2.text = @"0";
|
|
// _value2.font = [UIFont systemFontOfSize:7 weight:UIFontWeightMedium];
|
|
// _value2.backgroundColor = [ThemeColor colorWithHexString:@"#91C8FA"];
|
|
// _value2.layer.cornerRadius = 4;
|
|
// _value2.clipsToBounds = YES;
|
|
// }
|
|
// return _value2;
|
|
//}
|
|
//
|
|
//- (UILabel *)value3 {
|
|
// if (!_value3) {
|
|
// _value3 = [[UILabel alloc] init];
|
|
// _value3.textColor = [ThemeColor colorWithHexString:@"#824B2C"];
|
|
// _value3.textAlignment = NSTextAlignmentCenter;
|
|
// _value3.text = @"0";
|
|
// _value3.font = [UIFont systemFontOfSize:7 weight:UIFontWeightMedium];
|
|
// _value3.backgroundColor = [ThemeColor colorWithHexString:@"#F0A47B"];
|
|
// _value3.layer.cornerRadius = 4;
|
|
// _value3.clipsToBounds = YES;
|
|
// }
|
|
// return _value3;
|
|
//}
|
|
|
|
@end
|
|
|