220 lines
7.5 KiB
Objective-C
220 lines
7.5 KiB
Objective-C
//
|
|
// MaskResultPercentCell.m
|
|
// GIGA
|
|
//
|
|
// Created by lianxiang on 2018/9/20.
|
|
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
|
//
|
|
|
|
#import "MaskResultPercentCell.h"
|
|
|
|
@implementation MaskResultPercentCell
|
|
|
|
|
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
|
{
|
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
|
if (self) {
|
|
|
|
|
|
[self creatUI];
|
|
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-(void)creatUI{
|
|
|
|
self.backgroundColor = [UIColor whiteColor];
|
|
|
|
UIView *percentColorView = [[UIView alloc] init];
|
|
percentColorView.backgroundColor = GIGARGB(139, 231, 250, 1);
|
|
[self addSubview:percentColorView];
|
|
self.percentColorView = percentColorView;
|
|
|
|
[percentColorView mas_makeConstraints:^(MASConstraintMaker *make){
|
|
make.size.mas_equalTo(CGSizeMake(98, 127));
|
|
make.top.mas_equalTo(self.mas_top).offset(44);
|
|
make.left.mas_equalTo(self.mas_left).offset(60);
|
|
}];
|
|
|
|
[self layoutIfNeeded];
|
|
//默认0.5
|
|
CGFloat oilLaerH = percentColorView.frame.size.height * 0.5;
|
|
UIView *oilView= [[UIView alloc] init];
|
|
oilView.backgroundColor = GIGARGB(255, 191, 128, 1);
|
|
oilView.frame = CGRectMake(0,0,percentColorView.frame.size.width, 0);
|
|
self.oilView = oilView;
|
|
[percentColorView addSubview:oilView];
|
|
|
|
|
|
UIImageView *topLineimage = [[UIImageView alloc] init];
|
|
topLineimage.image = [UIImage imageNamed:@"result_line"];
|
|
[self addSubview:topLineimage];
|
|
[topLineimage mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.mas_left).offset(44);
|
|
make.size.mas_equalTo(CGSizeMake(120, 5.2));
|
|
make.top.mas_equalTo(21);
|
|
}];
|
|
UIImageView *shalouImage = [[UIImageView alloc] init];
|
|
shalouImage.image = [UIImage imageNamed:@"result_percent"];
|
|
[self addSubview:shalouImage];
|
|
[shalouImage mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.mas_equalTo(topLineimage.mas_bottom).offset(7);
|
|
make.left.mas_equalTo(self.mas_left).offset(60);
|
|
make.size.mas_equalTo(CGSizeMake(98, 149));
|
|
}];
|
|
|
|
UIImageView *bootpmLine = [[UIImageView alloc] init];
|
|
bootpmLine.image = [UIImage imageNamed:@"result_line"];
|
|
[self addSubview:bootpmLine];
|
|
[bootpmLine mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(self.mas_left).offset(44);
|
|
make.size.mas_equalTo(CGSizeMake(120, 5.2));
|
|
make.top.mas_equalTo(shalouImage.mas_bottom).offset(7);
|
|
|
|
}];
|
|
|
|
//皮肤水油比
|
|
UILabel *duibiLabel = [[UILabel alloc] init];
|
|
duibiLabel.text = @"皮肤水油比";
|
|
duibiLabel.textColor = GIGARGB(55, 55, 55, 1);
|
|
duibiLabel.font = GIGA_TEXTFONTBOLD(24);
|
|
[self addSubview:duibiLabel];
|
|
[duibiLabel sizeToFit];
|
|
[duibiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(topLineimage.mas_right).offset(13);
|
|
make.top.mas_equalTo(self.mas_top).offset(12);
|
|
}];
|
|
|
|
UIImageView *oilPercentgaurd =[[UIImageView alloc] init];
|
|
oilPercentgaurd.image = [UIImage imageNamed:@"result_oillider"];
|
|
[self addSubview:oilPercentgaurd];
|
|
[oilPercentgaurd mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(shalouImage.mas_right).offset(-2);
|
|
make.size.mas_equalTo(CGSizeMake(27,17));
|
|
make.top.mas_equalTo(duibiLabel.mas_bottom).mas_equalTo(30);
|
|
}];
|
|
|
|
//oil percent
|
|
UILabel *oilLabe = [[UILabel alloc]init];
|
|
oilLabe.text = @"50%";
|
|
oilLabe.textColor = GIGARGB(255, 191, 128, 1);
|
|
oilLabe.font = GIGA_TEXTFONTMEDIUM(36);
|
|
[self addSubview:oilLabe];
|
|
[oilLabe sizeToFit];
|
|
self.oilLabe = oilLabe;
|
|
[oilLabe mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(oilPercentgaurd.mas_right).offset(0);
|
|
make.bottom.mas_equalTo(oilPercentgaurd.mas_top).offset(19);
|
|
}];
|
|
|
|
UIImageView *watergaurd = [[UIImageView alloc] init];
|
|
watergaurd.image = [UIImage imageNamed:@"result_waterlider"];
|
|
[self addSubview:watergaurd];
|
|
[watergaurd mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(shalouImage.mas_right).offset(2);
|
|
make.size.mas_equalTo(CGSizeMake(42,19));
|
|
make.bottom.mas_equalTo(shalouImage.mas_bottom).mas_equalTo(-24);
|
|
}];
|
|
|
|
UILabel *waterlabe = [[UILabel alloc] init];
|
|
waterlabe.text = @"50%";
|
|
waterlabe.textColor = GIGARGB(139, 231, 250, 1);
|
|
waterlabe.font = GIGA_TEXTFONTMEDIUM(36);
|
|
[waterlabe sizeToFit];
|
|
[self addSubview:waterlabe];
|
|
self.waterlabe = waterlabe;
|
|
[waterlabe mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(watergaurd.mas_right).offset(-19);
|
|
make.bottom.mas_equalTo(watergaurd.mas_top).offset(12);
|
|
}];
|
|
|
|
UILabel *oneLabel = [[UILabel alloc] init];
|
|
oneLabel.text = @"1";
|
|
oneLabel.textColor = GIGARGB(240, 147, 147, 0.1);
|
|
oneLabel.alpha = 0.6;
|
|
oneLabel.font = GIGA_TEXTFONTMEDIUM(200);
|
|
[self addSubview:oneLabel];
|
|
[oneLabel sizeToFit];
|
|
[oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerY.mas_equalTo(self.mas_centerY);
|
|
make.right.mas_equalTo(self.mas_right).offset(-26);
|
|
}];
|
|
|
|
}
|
|
|
|
-(void)labProgresAction{
|
|
|
|
CALayer *presentLayer = self.oilView.layer.presentationLayer;
|
|
[self.oilView setNeedsDisplay];
|
|
|
|
CGFloat percent = CGRectGetHeight(presentLayer.frame) / self.percentColorView.frame.size.height*self.oilness;
|
|
//NSLog(@"%.2f",CGRectGetHeight(presentLayer.frame));
|
|
|
|
CGFloat curentOilprogress = percent * self.oilMAXProgress;
|
|
|
|
int oilInt = (int) curentOilprogress;
|
|
//NSLog(@"%d",oilInt);
|
|
self.oilLabe.text = [NSString stringWithFormat:@"%d%@",oilInt,@"%"];
|
|
|
|
|
|
CGFloat waterpercent = CGRectGetHeight(presentLayer.frame) / self.percentColorView.frame.size.height*(1-self.oilness);
|
|
CGFloat curentWaterprogress = waterpercent * self.waterMAXPorgress;
|
|
int waterInt = (int)curentWaterprogress;
|
|
self.waterlabe.text = [NSString stringWithFormat:@"%d%@",waterInt,@"%"];
|
|
|
|
}
|
|
|
|
- (void)awakeFromNib {
|
|
[super awakeFromNib];
|
|
// Initialization code
|
|
|
|
}
|
|
|
|
- (void)layoutSubviews{
|
|
|
|
}
|
|
|
|
-(void)loadCellData:(MaskTestResult *)model
|
|
{
|
|
self.oilness = [model.oiliness floatValue] ;
|
|
self.oilMAXProgress = [model.oiliness floatValue] *100 ;
|
|
self.waterMAXPorgress = 100 - self.oilMAXProgress;
|
|
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(labProgresAction)];
|
|
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
|
|
|
|
NSTimeInterval durition = 1.0;
|
|
|
|
if (!model.oiliness || [model.oiliness isEqualToString:@""] || [model.oiliness isKindOfClass:[NSNull class]]) {
|
|
model.oiliness = @"0.5";
|
|
}
|
|
|
|
CGFloat oil = [model.oiliness floatValue];
|
|
[UIView setAnimationDelegate:self];
|
|
[UIView animateWithDuration:durition animations:^{
|
|
|
|
self.oilView.frame = CGRectMake(0, 0, self.percentColorView.frame.size.width, self.percentColorView.frame.size.height * oil);
|
|
} completion:^(BOOL finished) {
|
|
[self.displayLink invalidate];
|
|
self.displayLink = nil;
|
|
self.oilLabe.text = model.oilinessPercent;
|
|
self.waterlabe.text = model.drynessPercent;
|
|
|
|
|
|
}];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
|
[super setSelected:selected animated:animated];
|
|
|
|
// Configure the view for the selected state
|
|
}
|
|
|
|
@end
|