Files
yinmeng-ios/xplan-ios/Main/Mine/View/SubViews/AnchorLevel/AnchorLevelProgressView.m

192 lines
6.3 KiB
Mathematica
Raw Normal View History

2022-12-13 21:09:48 +08:00
//
// 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;
2023-01-03 11:28:18 +08:00
if (_levelInfo.currentDiamond > _levelInfo.targetDiamond) {
self.titleLabel.text = @"已完成";
} else {
self.titleLabel.text = [NSString stringWithFormat:@"还差%ld钻可完成", (_levelInfo.targetDiamond - _levelInfo.currentDiamond)];
}
2022-12-13 21:09:48 +08:00
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;
2023-01-03 11:28:18 +08:00
if (_levelInfo.currentReply > _levelInfo.targetReply) {
self.titleLabel.text = @"已完成";
} else {
self.titleLabel.text = [NSString stringWithFormat:@"还差%.0f%@可完成", (_levelInfo.targetReply - _levelInfo.currentReply) * 100, @"%"];
}
2022-12-13 21:09:48 +08:00
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