261 lines
9.1 KiB
261 lines
9.1 KiB
![]()
2 years ago
|
//
|
||
|
// DeviceTabHeaderView.m
|
||
|
// tongxin
|
||
|
//
|
||
|
// Created by ecell on 2023/6/16.
|
||
|
// Copyright © 2023 xTT. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "DeviceTabHeaderView.h"
|
||
|
#import "User.h"
|
||
|
#import "Device.h"
|
||
|
|
||
|
@interface DeviceTabHeaderView ()
|
||
|
|
||
|
/// 设备头像
|
||
|
@property (nonatomic ,weak) UIImageView *iconImg;
|
||
|
|
||
|
/// 设备名称
|
||
|
@property (nonatomic ,weak) UILabel *nameLabel;
|
||
|
|
||
|
|
||
|
/// 设备电量图片
|
||
|
@property (nonatomic ,weak) UIImageView *batteryImg;
|
||
|
|
||
|
/// 设备电量
|
||
|
@property (nonatomic ,weak) UILabel *batteryLabel;
|
||
|
|
||
|
|
||
|
/// 运营商
|
||
|
@property (nonatomic ,weak) UIImageView *operatorImg;
|
||
|
|
||
|
@property (nonatomic ,weak) UILabel *line;
|
||
|
|
||
|
/// 是否在线图标
|
||
|
@property (nonatomic ,weak) UIImageView *signalImg;
|
||
|
|
||
|
@property (nonatomic ,weak) UILabel *titleLabel;
|
||
|
|
||
|
@property (nonatomic ,weak) UILabel *IdLabel;
|
||
|
|
||
|
@end
|
||
|
|
||
|
@implementation DeviceTabHeaderView
|
||
|
|
||
|
- (instancetype)initWithFrame:(CGRect)frame
|
||
|
{
|
||
|
self = [super initWithFrame:frame];
|
||
|
if (self)
|
||
|
{
|
||
|
self.frame = [UIScreen mainScreen].bounds;
|
||
|
self.backgroundColor = KKClearColor;
|
||
|
// self.layer.cornerRadius = 10;
|
||
|
// self.layer.masksToBounds = YES;
|
||
|
[self subHeadView];
|
||
|
}
|
||
|
return self;
|
||
|
}
|
||
|
|
||
|
- (void)subHeadView
|
||
|
{
|
||
|
UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:10 borderWidth:0 borderColor:KKWhiteColorColor];
|
||
|
[self addSubview:bgView];
|
||
|
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.mas_left);
|
||
|
make.top.equalTo(self.mas_top).offset(15);
|
||
|
make.right.equalTo(self.mas_right);
|
||
|
make.bottom.equalTo(self.mas_bottom);
|
||
|
}];
|
||
|
|
||
|
/// 设备头像
|
||
|
UIImageView *iconImg = [UIImageView new];
|
||
|
iconImg.layer.cornerRadius = 25;
|
||
|
iconImg.layer.masksToBounds = YES;
|
||
|
self.iconImg = iconImg;
|
||
|
[bgView addSubview:iconImg];
|
||
|
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(bgView.mas_left).offset(15);
|
||
|
make.top.equalTo(bgView.mas_top).offset(13);
|
||
|
make.size.mas_equalTo(CGSizeMake(50, 50));
|
||
|
}];
|
||
|
|
||
|
UIButton *btn = [UICommon ui_buttonSimple:CGRectZero font:Font_(0) normalColor:KKClearColor normalText:@"" click:^(id x) {
|
||
|
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
|
||
|
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"EditDeviceViewController"];
|
||
|
[vc setValue:@(NO) forKey:@"isAdd"];
|
||
|
[self.getViewController.navigationController pushViewController:vc animated:YES];
|
||
|
}];
|
||
|
[bgView addSubview:btn];
|
||
|
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.right.equalTo(bgView);
|
||
|
make.top.equalTo(bgView);
|
||
|
make.bottom.equalTo(iconImg.mas_bottom);
|
||
|
}];
|
||
|
|
||
|
|
||
|
|
||
|
/// 设备名称
|
||
|
UILabel *nameLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(16) textColor:KKTextColor text:@"" Radius:0];
|
||
|
self.nameLabel = nameLabel;
|
||
|
[bgView addSubview:nameLabel];
|
||
|
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(iconImg.mas_right).offset(20);
|
||
|
make.top.equalTo(iconImg.mas_top).offset(6.5);
|
||
|
}];
|
||
|
|
||
|
// /// 编辑图片
|
||
|
// UIImageView *editImg = [UICommon ui_imageView:CGRectZero fileName:@"icon_home_editor"];
|
||
|
// [bgView addSubview:editImg];
|
||
|
// [editImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
// make.left.equalTo(nameLabel.mas_right).offset(15);
|
||
|
// make.centerY.equalTo(nameLabel.mas_centerY);
|
||
|
// make.size.mas_equalTo(CGSizeMake(11, 11));
|
||
|
// }];
|
||
|
|
||
|
//
|
||
|
// /// 设备电量
|
||
|
// UILabel *batteryLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:KKTextColor text:@"" Radius:0];
|
||
|
// self.batteryLabel = batteryLabel;
|
||
|
// [bgView addSubview:batteryLabel];
|
||
|
// [batteryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
// make.left.equalTo(batteryImg.mas_right).offset(10);
|
||
|
// make.centerY.equalTo(batteryImg.mas_centerY);
|
||
|
// }];
|
||
|
|
||
|
UILabel *IdLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:RGB(133, 133, 133) text:@"" Radius:0];
|
||
|
self.IdLabel = IdLabel;
|
||
|
[bgView addSubview:IdLabel];
|
||
|
[IdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(nameLabel);
|
||
|
make.top.equalTo(nameLabel.mas_bottom).offset(10);
|
||
|
}];
|
||
|
|
||
|
|
||
|
/// 右箭头图片
|
||
|
UIImageView *rightImg = [UICommon ui_imageView:CGRectZero fileName:@"comm_right_icon"];
|
||
|
[bgView addSubview:rightImg];
|
||
|
[rightImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(bgView.mas_right).inset(18);
|
||
|
make.centerY.equalTo(iconImg.mas_centerY);
|
||
|
make.size.mas_equalTo(CGSizeMake(8, 15));
|
||
|
}];
|
||
|
|
||
|
UILabel *ttLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(12) textColor:RGB(133, 133, 133) text:@"编辑资料" Radius:0];
|
||
|
[bgView addSubview:ttLabel];
|
||
|
[ttLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.right.equalTo(rightImg.mas_left).inset(10);
|
||
|
make.centerY.equalTo(rightImg.mas_centerY);
|
||
|
}];
|
||
|
|
||
|
NSArray *titleArr = @[@"当前电量",@"未连接",];
|
||
|
CGFloat ww = (ScreenWidth-30)/titleArr.count;
|
||
|
|
||
|
for (int i = 1; i < titleArr.count; i++)
|
||
|
{
|
||
|
UILabel *line = [UILabel new];
|
||
|
line.backgroundColor = RGB(235, 235, 235);
|
||
|
self.line = line;
|
||
|
[self addSubview:line];
|
||
|
[line mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.mas_left).offset(i*ww);
|
||
|
make.top.equalTo(iconImg.mas_bottom).offset(17);
|
||
|
//make.bottom.equalTo(bgView.mas_bottom).inset(26);
|
||
|
make.size.mas_equalTo(CGSizeMake(1, 45));
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < titleArr.count; i++)
|
||
|
{
|
||
|
UILabel *label = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(10) textColor:RGB(133, 133, 133) text:titleArr[i] Radius:0];
|
||
|
if (i == 0) self.batteryLabel = label;
|
||
|
if (i == 1) self.titleLabel = label;
|
||
|
[self addSubview:label];
|
||
|
[label mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.left.equalTo(self.mas_left).offset(i*ww);
|
||
|
make.top.equalTo(self.line.mas_centerY).offset(5);
|
||
|
make.width.mas_equalTo(ww);
|
||
|
}];
|
||
|
|
||
|
/// 当前电量
|
||
|
UIImageView *signalImg = [UICommon ui_imageView:CGRectZero fileName:@""];
|
||
|
[self addSubview:signalImg];
|
||
|
|
||
|
if (i == 0)
|
||
|
{
|
||
|
self.batteryImg = signalImg;
|
||
|
[signalImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(label.mas_centerX);
|
||
|
make.bottom.equalTo(self.line.mas_centerY).inset(5);
|
||
|
make.size.mas_equalTo(CGSizeMake(25, 10));
|
||
|
}];
|
||
|
}
|
||
|
else if (i == 1)
|
||
|
{
|
||
|
self.signalImg = signalImg;
|
||
|
[signalImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(label.mas_centerX);
|
||
|
make.centerY.equalTo(self.batteryImg);
|
||
|
make.size.mas_equalTo(CGSizeMake(15, 15));
|
||
|
}];
|
||
|
}
|
||
|
else if (i == 2)
|
||
|
{
|
||
|
[signalImg mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
|
make.centerX.equalTo(label.mas_centerX);
|
||
|
make.centerY.equalTo(self.batteryImg);
|
||
|
make.size.mas_equalTo(CGSizeMake(15, 15));
|
||
|
}];
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
- (void)setModel
|
||
|
{
|
||
|
UIImage *defaImage;
|
||
|
self.nameLabel.text = cUser.cDevice.name;
|
||
|
self.IdLabel.text = [NSString stringWithFormat:@"账号:%@",cUser.cDevice.imei];
|
||
|
if([cUser.cDevice.sex isEqualToString:@"girl"])
|
||
|
defaImage = [myHelper getImageWithName: @"icon_girl_head_portrait_1"];
|
||
|
else
|
||
|
defaImage = [myHelper getImageWithName: @"icon_boy_head_portrait_1"];
|
||
|
[self.iconImg sd_setImageWithURL:[NSURL URLWithString:cUser.cDevice.avator]
|
||
|
placeholderImage:defaImage];
|
||
|
self.signalImg.image = cUser.cDevice.onlineStatus.boolValue ? ImageName_(@"icon_device_connected") : ImageName_(@"icon_device_unconnected");
|
||
|
self.titleLabel.text = cUser.cDevice.onlineStatus.boolValue ? @"已连接" : @"未连接";
|
||
|
NSInteger battery = cUser.cDevice.battery.integerValue;
|
||
|
NSString *imageName = @"";
|
||
|
if(battery == 0)
|
||
|
imageName = @"battery_0";
|
||
|
else if (battery < 10)
|
||
|
imageName = @"battery_low";
|
||
|
else if (battery < 20)
|
||
|
imageName = @"battery_1";
|
||
|
else if (battery < 30)
|
||
|
imageName = @"battery_2";
|
||
|
else if (battery < 40)
|
||
|
imageName = @"battery_3";
|
||
|
else if (battery < 50)
|
||
|
imageName = @"battery_4";
|
||
|
else if (battery < 60)
|
||
|
imageName = @"battery_4";
|
||
|
else if (battery < 70)
|
||
|
imageName = @"battery_6";
|
||
|
else if (battery < 80)
|
||
|
imageName = @"battery_7";
|
||
|
else if (battery < 90)
|
||
|
imageName = @"battery_8";
|
||
|
else if (battery < 100)
|
||
|
imageName = @"battery_9";
|
||
|
else
|
||
|
imageName = @"battery_10";
|
||
|
|
||
|
self.batteryImg.image = [myHelper getImageWithName:imageName];
|
||
|
self.batteryLabel.text = [NSString stringWithFormat:@"当前电量:%ld%%",battery];
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
@end
|