192 lines
6.3 KiB
Objective-C
192 lines
6.3 KiB
Objective-C
//
|
|
// AnchorLevelProgressView.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/12/13.
|
|
//
|
|
|
|
#import "AnchorLevelProgressView.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
///Tool
|
|
#import "ThemeColor.h"
|
|
#import "UIImage+Utils.h"
|
|
///Model
|
|
#import "AnchorLevelModel.h"
|
|
|
|
@interface AnchorLevelProgressView ()
|
|
///任务
|
|
@property (nonatomic,strong) UILabel *taskLabel;
|
|
///背景
|
|
@property (nonatomic,strong) UIView *backView;
|
|
///当前的等级
|
|
@property (nonatomic,strong) UILabel *currentLevelLabel;
|
|
///下一个等级
|
|
@property (nonatomic,strong) UILabel *nextLevelLabel;
|
|
///显示内容
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
///进度条
|
|
@property (nonatomic,strong) UIImageView *progressView;
|
|
|
|
@end
|
|
|
|
@implementation AnchorLevelProgressView
|
|
|
|
|
|
- (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.taskLabel];
|
|
[self addSubview:self.backView];
|
|
|
|
[self.backView addSubview:self.progressView];
|
|
[self.backView addSubview:self.currentLevelLabel];
|
|
[self.backView addSubview:self.nextLevelLabel];
|
|
[self.backView addSubview:self.titleLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
|
|
[self.taskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self).offset(18);
|
|
make.top.mas_equalTo(self);
|
|
}];
|
|
|
|
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self);
|
|
make.width.mas_equalTo(260);
|
|
make.height.mas_equalTo(16);
|
|
make.top.mas_equalTo(self.taskLabel.mas_bottom).offset(8);
|
|
}];
|
|
|
|
[self.currentLevelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.backView);
|
|
make.left.mas_equalTo(self.backView).offset(5);
|
|
}];
|
|
|
|
[self.nextLevelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.backView);
|
|
make.right.mas_equalTo(self.backView).offset(-5);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.currentLevelLabel.mas_right).offset(2);
|
|
make.centerY.mas_equalTo(self.backView);
|
|
}];
|
|
|
|
|
|
[self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.bottom.mas_equalTo(self.backView);
|
|
make.width.mas_equalTo(20);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (void)setLevelInfo:(AnchorLevelModel *)levelInfo {
|
|
_levelInfo = levelInfo;
|
|
if (_levelInfo) {
|
|
self.currentLevelLabel.text = _levelInfo.grade;
|
|
self.nextLevelLabel.text = _levelInfo.nextGrade;
|
|
if (self.isDiamond) {
|
|
NSString * diamond = [NSString stringWithFormat:@"%ld", _levelInfo.currentDiamond];
|
|
NSString * task = [NSString stringWithFormat:@"收礼钻石数:%@", diamond];
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:task attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[ThemeColor colorWithHexString:@"#8A8CAB"]}];
|
|
[attribute addAttribute:NSForegroundColorAttributeName value:[ThemeColor colorWithHexString:@"#F86099"] range:[task rangeOfString:diamond]];
|
|
self.taskLabel.attributedText = attribute;
|
|
if (_levelInfo.currentDiamond > _levelInfo.targetDiamond) {
|
|
self.titleLabel.text = @"已完成";
|
|
} else {
|
|
self.titleLabel.text = [NSString stringWithFormat:@"还差%ld钻可完成", (_levelInfo.targetDiamond - _levelInfo.currentDiamond)];
|
|
}
|
|
|
|
CGFloat itemWidth = ((CGFloat)_levelInfo.currentDiamond / (CGFloat)_levelInfo.targetDiamond)* 260;
|
|
[self.progressView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(itemWidth);
|
|
}];
|
|
} else {
|
|
NSString * diamond = [NSString stringWithFormat:@"%.0f%@", _levelInfo.currentReply * 100, @"%"];
|
|
NSString * task = [NSString stringWithFormat:@"新用户私聊回复率:%@", diamond];
|
|
NSMutableAttributedString * attribute = [[NSMutableAttributedString alloc] initWithString:task attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11], NSForegroundColorAttributeName:[ThemeColor colorWithHexString:@"#8A8CAB"]}];
|
|
[attribute addAttribute:NSForegroundColorAttributeName value:[ThemeColor colorWithHexString:@"#F86099"] range:[task rangeOfString:diamond]];
|
|
self.taskLabel.attributedText = attribute;
|
|
if (_levelInfo.currentReply > _levelInfo.targetReply) {
|
|
self.titleLabel.text = @"已完成";
|
|
} else {
|
|
self.titleLabel.text = [NSString stringWithFormat:@"还差%.0f%@可完成", (_levelInfo.targetReply - _levelInfo.currentReply) * 100, @"%"];
|
|
}
|
|
|
|
|
|
CGFloat itemWidth = _levelInfo.currentReply * 260;
|
|
[self.progressView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(itemWidth);
|
|
}];
|
|
}
|
|
}
|
|
}
|
|
|
|
- (UILabel *)taskLabel {
|
|
if (!_taskLabel) {
|
|
_taskLabel = [[UILabel alloc] init];
|
|
}
|
|
return _taskLabel;
|
|
}
|
|
|
|
- (UILabel *)currentLevelLabel {
|
|
if (!_currentLevelLabel) {
|
|
_currentLevelLabel = [[UILabel alloc] init];
|
|
_currentLevelLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
|
_currentLevelLabel.textColor = [UIColor whiteColor];
|
|
}
|
|
return _currentLevelLabel;
|
|
}
|
|
|
|
- (UILabel *)nextLevelLabel {
|
|
if (!_nextLevelLabel) {
|
|
_nextLevelLabel = [[UILabel alloc] init];
|
|
_nextLevelLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
|
|
_nextLevelLabel.textColor = [UIColor whiteColor];
|
|
}
|
|
return _nextLevelLabel;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.font = [UIFont systemFontOfSize:10];
|
|
_titleLabel.textColor = [UIColor whiteColor];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UIView *)backView {
|
|
if (!_backView) {
|
|
_backView = [[UIView alloc] init];
|
|
_backView.backgroundColor = UIColorRGBAlpha(0x000124, 0.1);
|
|
_backView.layer.masksToBounds = YES;
|
|
_backView.layer.cornerRadius = 8;
|
|
}
|
|
return _backView;
|
|
}
|
|
|
|
- (UIImageView *)progressView {
|
|
if (!_progressView) {
|
|
_progressView = [[UIImageView alloc] init];
|
|
_progressView.userInteractionEnabled = YES;
|
|
_progressView.image = [UIImage gradientColorImageFromColors:@[[ThemeColor colorWithHexString:@"#FFAAAA"], [ThemeColor colorWithHexString:@"#FF5A88"]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)];
|
|
_progressView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_progressView.layer.masksToBounds = YES;
|
|
_progressView.layer.cornerRadius = 8;
|
|
}
|
|
return _progressView;
|
|
}
|
|
|
|
@end
|