You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
287 lines
9.8 KiB
287 lines
9.8 KiB
![]()
2 years ago
|
//
|
||
|
// BloodAndOxygenHeaderView.m
|
||
|
// tongxin
|
||
|
//
|
||
|
// Created by ecell on 2023/4/27.
|
||
|
// Copyright © 2023 xTT. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "BloodAndOxygenHeaderView.h"
|
||
|
#import "UILabel+BezierAnimation.h"
|
||
|
#import "FBYLineGraphView.h"
|
||
|
|
||
|
@interface BloodAndOxygenHeaderView ()
|
||
|
|
||
|
@property (nonatomic ,weak) UIImageView *iconImg;
|
||
|
|
||
|
@property (nonatomic ,weak) UILabel *msgLabel;
|
||
|
|
||
|
@property (nonatomic ,weak) UILabel *tiLabel;
|
||
|
|
||
|
@property (nonatomic ,weak) UILabel *timeLabel;
|
||
|
|
||
|
@property (nonatomic ,weak) UIView *tiView;
|
||
|
|
||
|
/// 折线图
|
||
|
@property (strong, nonatomic)FBYLineGraphView *LineGraphView;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation BloodAndOxygenHeaderView
|
||
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
{
|
||
|
self = [super initWithFrame:frame];
|
||
|
if (self)
|
||
|
{
|
||
|
self.backgroundColor = UIColor.whiteColor;
|
||
|
[self subHeaderView];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)setTypes:(NSInteger)types
|
||
|
{
|
||
|
_types = types;
|
||
|
self.iconImg.image = types == 888 ? ImageName_(@"icon_blood_pressure") : ImageName_(@"icon_blood_oxgeng");
|
||
|
self.tiLabel.text = types == 888 ? @"mmHg" : @"SpO2";
|
||
|
}
|
||
|
- (void)setDayTime:(NSString *)dayTime
|
||
|
{
|
||
|
_dayTime = dayTime;
|
||
|
}
|
||
|
|
||
|
- (void)setMsgDic:(NSDictionary *)msgDic
|
||
|
{
|
||
|
_msgDic = msgDic;
|
||
|
NSArray *dataList = msgDic[@"dataListDict"][self.dayTime];
|
||
|
NSLog(@"%@",dataList);
|
||
|
self.timeLabel.text = @"上次时间:--";
|
||
|
if(dataList.count > 0)
|
||
|
self.timeLabel.text = [NSString stringWithFormat:@"上次时间:%@" ,[self getTimeFromTimestamp_n:msgDic[@"lastDataTime"]]];
|
||
|
if (_LineGraphView)
|
||
|
{
|
||
|
_LineGraphView = nil;
|
||
|
[_LineGraphView removeFromSuperview];
|
||
|
}
|
||
|
UIImage *img = ImageName_(@"icon_blood_box");
|
||
|
_LineGraphView = [[FBYLineGraphView alloc] initWithFrame:CGRectMake(15, Adapted(img.size.height)+80, ScreenWidth-30,Adapted(190))];
|
||
|
[self addSubview:_LineGraphView];
|
||
|
_LineGraphView.MainColor = mainColor;
|
||
|
_LineGraphView.Ycount = 5; // Y轴分割个数(包含0在内的)
|
||
|
_LineGraphView.XYAxisColor = [UIColor lightGrayColor];
|
||
|
//_LineGraphView.isBO = 1;
|
||
|
if (self.types == 888)
|
||
|
{
|
||
|
self.tiView.hidden = NO;
|
||
|
NSString *totext = [NSString stringWithFormat:@"/%@",msgDic[@"lastSysBlood"]];
|
||
|
self.msgLabel.attributedText = [self labelFontSize:[NSString stringWithFormat:@"%@%@",msgDic[@"lastDiaBlood"],totext] toText:totext];
|
||
|
|
||
|
//_LineGraphView.yTitleArray = @[@"0",@"70",@"100",@"130",@"160"];
|
||
|
_LineGraphView.maxValue = 160; // Y轴最大值
|
||
|
//_LineGraphView.minValue = 70;
|
||
|
// NSArray *dataList = msgDic[@"dataListDict"][self.dayTime];
|
||
|
NSMutableArray *diastolicDataList = [NSMutableArray array];
|
||
|
NSMutableArray *systolicDataList = [NSMutableArray array];
|
||
|
|
||
|
for (NSDictionary *data in dataList)
|
||
|
{
|
||
|
NSMutableDictionary *systolicDic = [NSMutableDictionary dictionary];
|
||
|
[systolicDic setValue:data[@"systolicBlood"] forKey:@"systolicBlood"];
|
||
|
[systolicDic setValue:data[@"timestamp"] forKey:@"timestamp"];
|
||
|
[systolicDataList addObject:systolicDic];
|
||
|
|
||
|
|
||
|
NSMutableDictionary *diastolicDic = [NSMutableDictionary dictionary];
|
||
|
[diastolicDic setValue:data[@"diastolicBlood"] forKey:@"diastolicBlood"];
|
||
|
[diastolicDic setValue:data[@"timestamp"] forKey:@"timestamp"];
|
||
|
[diastolicDataList addObject:diastolicDic];
|
||
|
}
|
||
|
[_LineGraphView setXMarkWithDay:self.dayTime TitlesTimeAndValues:systolicDataList titleKey:@"timestamp" valueKey:@"systolicBlood"];
|
||
|
[_LineGraphView mapping];
|
||
|
|
||
|
[_LineGraphView setXMarkWithDay1:self.dayTime TitlesTimeAndValues:diastolicDataList titleKey:@"timestamp" valueKey:@"diastolicBlood"];
|
||
|
[_LineGraphView mapping1];
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
|
||
|
self.msgLabel.text = [NSString stringWithFormat:@"%@",msgDic[@"lastOxygen"]];
|
||
|
self.tiView.hidden = YES;
|
||
|
//_LineGraphView.yTitleArray = @[@"0",@"82",@"90",@"98",@"105"];
|
||
|
_LineGraphView.maxValue = 105; // Y轴最大值
|
||
|
//_LineGraphView.minValue = 82;
|
||
|
_LineGraphView.upperValue = [msgDic[@"upper"] floatValue];
|
||
|
_LineGraphView.lowerValue = [msgDic[@"lower"] floatValue];
|
||
|
// NSArray *dataList = msgDic[@"dataListDict"][self.dayTime];
|
||
|
NSMutableArray *tampDataList = [NSMutableArray array];
|
||
|
for (NSDictionary *data in dataList)
|
||
|
{
|
||
|
NSMutableDictionary *tampDic = [NSMutableDictionary dictionary];
|
||
|
[tampDic setValue:data[@"data"] forKey:@"data"];
|
||
|
[tampDic setValue:data[@"timestamp"] forKey:@"timestamp"];
|
||
|
[tampDataList addObject:tampDic];
|
||
|
}
|
||
|
[_LineGraphView setXMarkWithDay:self.dayTime TitlesTimeAndValues:tampDataList titleKey:@"timestamp" valueKey:@"data"];
|
||
|
[_LineGraphView mapping];
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
- (void)subHeaderView
|
||
|
{
|
||
|
UIImageView *bgImg = [[UIImageView alloc] init];
|
||
|
bgImg.image = ImageName_(@"icon_blood_box");
|
||
|
[self addSubview:bgImg];
|
||
|
[bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self);
|
||
|
make.top.equalTo(self).offset(20);
|
||
|
make.size.mas_equalTo(CGSizeMake(Adapted(bgImg.image.size.width), Adapted(bgImg.image.size.height)));
|
||
|
}];
|
||
|
|
||
|
|
||
|
UIImageView *iconImg = [[UIImageView alloc] init];
|
||
|
iconImg.image = ImageName_(@"icon_blood_oxgeng");
|
||
|
self.iconImg = iconImg;
|
||
|
[self addSubview:iconImg];
|
||
|
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self);
|
||
|
make.top.equalTo(bgImg).offset(30);
|
||
|
make.size.mas_equalTo(CGSizeMake(Adapted(iconImg.image.size.width), Adapted(iconImg.image.size.height)));
|
||
|
}];
|
||
|
|
||
|
UILabel *msgLabel = [UILabel new];
|
||
|
msgLabel.font = FontBoldADA_(35);
|
||
|
msgLabel.textColor = UIColor.redColor;
|
||
|
self.msgLabel = msgLabel;
|
||
|
[self addSubview:msgLabel];
|
||
|
[msgLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self);
|
||
|
make.centerY.equalTo(bgImg.mas_centerY).offset(10);
|
||
|
}];
|
||
|
|
||
|
UILabel *tiLabel = [UILabel new];
|
||
|
tiLabel.font = FontADA_(15);
|
||
|
tiLabel.textColor = KKGrey143;
|
||
|
tiLabel.text = @"mmHg";
|
||
|
self.tiLabel = tiLabel;
|
||
|
[self addSubview:tiLabel];
|
||
|
[tiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self);
|
||
|
make.bottom.equalTo(bgImg.mas_bottom).inset(10);
|
||
|
}];
|
||
|
|
||
|
UILabel *timeLabel = [UILabel new];
|
||
|
timeLabel.font = FontADA_(15);
|
||
|
timeLabel.textColor = KKGrey143;
|
||
|
self.timeLabel = timeLabel;
|
||
|
[self addSubview:timeLabel];
|
||
|
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(self);
|
||
|
make.top.equalTo(bgImg.mas_bottom).offset(15);
|
||
|
}];
|
||
|
|
||
|
|
||
|
UIImageView *line = [UIImageView new];
|
||
|
line.backgroundColor = KKGrey219;
|
||
|
[self addSubview: line];
|
||
|
[line mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.right.equalTo(self);
|
||
|
make.top.equalTo(timeLabel.mas_bottom).offset(20);
|
||
|
make.height.mas_equalTo(0.5);
|
||
|
}];
|
||
|
|
||
|
UIView *tiView = [UIView new];
|
||
|
tiView.hidden = YES;
|
||
|
self.tiView = tiView;
|
||
|
[self addSubview:tiView];
|
||
|
[tiView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.right.equalTo(self);
|
||
|
make.top.equalTo(line.mas_bottom).offset(Adapted(190)+15);
|
||
|
make.height.mas_equalTo(Adapted(90));
|
||
|
}];
|
||
|
|
||
|
UILabel *redLabel = [UILabel new];
|
||
|
redLabel.backgroundColor = UIColor.redColor;
|
||
|
[tiView addSubview:redLabel];
|
||
|
[redLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(tiView).offset(15);
|
||
|
make.top.equalTo(tiView);
|
||
|
make.size.mas_equalTo(CGSizeMake(35, 18));
|
||
|
}];
|
||
|
|
||
|
UILabel *tisLabel = [UILabel new];
|
||
|
tisLabel.text = @"舒张压";
|
||
|
tisLabel.textColor = KKGrey102;
|
||
|
[tiView addSubview:tisLabel];
|
||
|
[tisLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(redLabel.mas_right).offset(10);
|
||
|
make.centerY.equalTo(redLabel);
|
||
|
}];
|
||
|
|
||
|
UILabel *mainLabel = [UILabel new];
|
||
|
mainLabel.backgroundColor = mainColor;
|
||
|
[tiView addSubview:mainLabel];
|
||
|
[mainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(tiView).offset(15);
|
||
|
make.top.equalTo(redLabel.mas_bottom).offset(20);
|
||
|
make.size.mas_equalTo(CGSizeMake(35, 18));
|
||
|
}];
|
||
|
|
||
|
UILabel *tisLabel1 = [UILabel new];
|
||
|
tisLabel1.text = @"收缩压";
|
||
|
tisLabel1.textColor = KKGrey102;
|
||
|
[tiView addSubview:tisLabel1];
|
||
|
[tisLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(mainLabel.mas_right).offset(10);
|
||
|
make.centerY.equalTo(mainLabel);
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
/// 指定字符大小
|
||
|
/// @param text 内容
|
||
|
- (NSAttributedString *)labelFontSize:(NSString *)text toText:(NSString *)totext
|
||
|
{
|
||
|
NSRange symbolRange = [text rangeOfString:totext];
|
||
|
|
||
|
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text];
|
||
|
if (symbolRange.location != NSNotFound) {
|
||
|
|
||
|
[string addAttribute:NSForegroundColorAttributeName value:mainColor range:NSMakeRange(symbolRange.location, symbolRange.length)];
|
||
|
}
|
||
|
return string;
|
||
|
}
|
||
|
|
||
|
|
||
|
/// 之间戳转换成时间
|
||
|
/// @param time 时间戳
|
||
|
- (NSString *)getTimeFromTimestamp_n:(NSString *)time
|
||
|
{
|
||
|
|
||
|
//将对象类型的时间转换为NSDate类型
|
||
|
NSDate *myDate = [NSDate dateWithTimeIntervalSince1970:[time integerValue]];
|
||
|
//设置时间格式
|
||
|
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
|
||
|
[formatter setDateFormat:@"YYYY/MM/dd HH:mm"];
|
||
|
//将时间转换为字符串
|
||
|
NSString *timeStr = [formatter stringFromDate:myDate];
|
||
|
|
||
|
return timeStr;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/*
|
||
|
// Only override drawRect: if you perform custom drawing.
|
||
|
// An empty implementation adversely affects performance during animation.
|
||
|
- (void)drawRect:(CGRect)rect {
|
||
|
// Drawing code
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
@end
|