2023-07-14 18:50:55 +08:00
|
|
|
|
//
|
|
|
|
|
// YMRoomRankEntranceView.m
|
|
|
|
|
// YUMI
|
|
|
|
|
//
|
|
|
|
|
// Created by YUMI on 2022/4/27.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "XPRoomRankEntranceView.h"
|
|
|
|
|
///Third
|
|
|
|
|
#import <Masonry/Masonry.h>
|
|
|
|
|
#import "DJDKMIMOMColor.h"
|
|
|
|
|
///Tool
|
|
|
|
|
#import "NetImageView.h"
|
|
|
|
|
|
|
|
|
|
@interface XPRoomRankEntranceView ()
|
|
|
|
|
|
|
|
|
|
///背景图
|
|
|
|
|
@property (nonatomic, strong) UIView *bgView;
|
|
|
|
|
///礼物值
|
|
|
|
|
@property (nonatomic, strong) UILabel *titleLabel;
|
|
|
|
|
///箭头图标
|
|
|
|
|
@property (nonatomic, strong) UIImageView *iconImageView;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation XPRoomRankEntranceView
|
|
|
|
|
|
|
|
|
|
- (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];
|
2024-05-21 14:17:30 +08:00
|
|
|
|
[self.bgView addSubview:self.titleLabel];
|
|
|
|
|
[self.bgView addSubview:self.iconImageView];
|
|
|
|
|
|
2023-07-14 18:50:55 +08:00
|
|
|
|
}
|
2024-05-21 14:17:30 +08:00
|
|
|
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
|
|
|
|
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.top.bottom.trailing.leading.equalTo(self);
|
|
|
|
|
}];
|
2023-09-27 12:35:29 +08:00
|
|
|
|
|
|
|
|
|
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
2024-05-21 14:17:30 +08:00
|
|
|
|
make.centerY.mas_equalTo(self.bgView);
|
2024-05-22 19:36:51 +08:00
|
|
|
|
make.leading.mas_equalTo(26);
|
2024-04-10 17:39:37 +08:00
|
|
|
|
make.trailing.mas_equalTo(-4);
|
2023-09-27 12:35:29 +08:00
|
|
|
|
}];
|
|
|
|
|
[self.iconImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
2024-05-22 19:36:51 +08:00
|
|
|
|
make.width.mas_equalTo(18);
|
|
|
|
|
make.height.mas_equalTo(15);
|
2024-05-21 14:17:30 +08:00
|
|
|
|
make.centerY.mas_equalTo(self.bgView);
|
2024-05-22 19:36:51 +08:00
|
|
|
|
make.leading.mas_equalTo(5);
|
2023-09-27 12:35:29 +08:00
|
|
|
|
}];
|
2023-07-14 18:50:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-21 12:38:03 +08:00
|
|
|
|
BOOL isNumeric(NSString *string) {
|
|
|
|
|
NSError *error = nil;
|
|
|
|
|
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^[0-9]+$" options:0 error:&error];
|
|
|
|
|
if (error) {
|
|
|
|
|
NSLog(@"Error creating regex: %@", error.localizedDescription);
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
NSRange range = NSMakeRange(0, string.length);
|
|
|
|
|
NSTextCheckingResult *match = [regex firstMatchInString:string options:0 range:range];
|
|
|
|
|
return match != nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSString *)formatCoins:(NSInteger)coins {
|
|
|
|
|
NSString *formattedString;
|
|
|
|
|
if (coins >= 1000000) {
|
|
|
|
|
// 转换为M单位,保留小数点后1位
|
|
|
|
|
double valueInMillions = coins / 1000000.0;
|
|
|
|
|
formattedString = [NSString stringWithFormat:@"%.1fM", valueInMillions];
|
|
|
|
|
} else if (coins >= 1000) {
|
|
|
|
|
// 转换为K单位,保留小数点后1位
|
|
|
|
|
double valueInThousands = coins / 1000.0;
|
|
|
|
|
formattedString = [NSString stringWithFormat:@"%.1fK", valueInThousands];
|
|
|
|
|
} else {
|
|
|
|
|
// 保持原始值
|
|
|
|
|
formattedString = [NSString stringWithFormat:@"%ld", (long)coins];
|
|
|
|
|
}
|
|
|
|
|
return formattedString;
|
|
|
|
|
}
|
2023-07-14 18:50:55 +08:00
|
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
|
- (void)setTitle:(NSString *)title {
|
2024-06-21 16:14:36 +08:00
|
|
|
|
if (![title isKindOfClass:[NSString class]]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (title.length == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-21 12:38:03 +08:00
|
|
|
|
if (isNumeric(title)) {
|
2024-06-21 16:14:36 +08:00
|
|
|
|
_titleLabel.text = [self formatCoins:[title integerValue]];
|
2024-06-21 12:38:03 +08:00
|
|
|
|
} else {
|
2024-06-21 16:14:36 +08:00
|
|
|
|
_titleLabel.text = title;
|
2024-06-21 12:38:03 +08:00
|
|
|
|
}
|
2023-07-14 18:50:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIView *)bgView {
|
|
|
|
|
if (_bgView == nil) {
|
|
|
|
|
_bgView = [[UIView alloc] init];
|
2024-05-21 14:17:30 +08:00
|
|
|
|
_bgView.backgroundColor = UIColorRGBAlpha(0xFFFFFF, 0.2);
|
2023-07-14 18:50:55 +08:00
|
|
|
|
_bgView.layer.cornerRadius = 12;
|
|
|
|
|
_bgView.layer.masksToBounds = YES;
|
|
|
|
|
}
|
|
|
|
|
return _bgView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIImageView *)iconImageView {
|
|
|
|
|
if (_iconImageView == nil) {
|
|
|
|
|
_iconImageView = [[UIImageView alloc] init];
|
2024-05-21 14:17:30 +08:00
|
|
|
|
_iconImageView.image = [[UIImage imageNamed:@"room_rank_iocn"]ms_SetImageForRTL];
|
2023-07-14 18:50:55 +08:00
|
|
|
|
_iconImageView.contentMode = UIViewContentModeScaleAspectFit;
|
2024-04-10 17:39:37 +08:00
|
|
|
|
|
2023-07-14 18:50:55 +08:00
|
|
|
|
}
|
|
|
|
|
return _iconImageView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UILabel *)titleLabel {
|
|
|
|
|
if (_titleLabel == nil) {
|
|
|
|
|
_titleLabel = [[UILabel alloc] init];
|
2024-05-21 14:17:30 +08:00
|
|
|
|
_titleLabel.textColor = [UIColor colorWithWhite:1 alpha:0.8];
|
|
|
|
|
_titleLabel.font = [UIFont systemFontOfSize:9 weight:UIFontWeightBold];
|
2024-06-21 16:14:36 +08:00
|
|
|
|
_titleLabel.text = @"0"; YMLocalizedString(@"XPRoomRankEntranceView0");
|
2024-04-10 17:39:37 +08:00
|
|
|
|
_titleLabel.numberOfLines = 2;
|
2023-07-14 18:50:55 +08:00
|
|
|
|
}
|
|
|
|
|
return _titleLabel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end
|