ifish/Ifish/controllers/FishTinkController/maincontroller/CenterontrolControllers/RuSunTemp/RuSunIndependence/HaveHotCoolWenDuPicview.m

181 lines
5.4 KiB
Objective-C

//
// HaveHotCoolWenDuPicview.m
// Ifish
//
// Created by imac on 2017/6/15.
// Copyright © 2017年 lianlian. All rights reserved.
//
#import "HaveHotCoolWenDuPicview.h"
@interface HaveHotCoolWenDuPicview()<UIPickerViewDataSource,UIPickerViewDelegate>
@end
@implementation HaveHotCoolWenDuPicview
-(instancetype)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if (self) {
[self initPicview];
}
return self;
}
-(void)initPicview{
CGFloat imgWid= kScreenSize.width - 40*2;
CGFloat imHeight= imgWid*1.6;
self.backgroundColor=[UIColor colorWithWhite:0 alpha:0.5];
_picBackImg
=[[UIImageView alloc]initWithFrame:CGRectMake(40,kScreenSize.height/2-imHeight/2, imgWid, imHeight)];
_picBackImg.image=[UIImage imageNamed:@"Box"];
[self addSubview:_picBackImg];
_picBackImg.userInteractionEnabled=YES;
CGFloat titleW = (_picBackImg.frame.size.width-10*2)/2;
UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(10,0, titleW, 47)];
title.text=@"温度控制";
title.font=[UIFont systemFontOfSize:20];
title.textAlignment=NSTextAlignmentCenter;
//title.backgroundColor = [UIColor redColor];
[_picBackImg addSubview:title];
_cateSwich = [UIButton buttonWithType:UIButtonTypeCustom];
_cateSwich.frame = CGRectMake(imgWid - 100 - 10, 0, 100, 47);
[_cateSwich addTarget:self action:@selector(cateSwichAction:) forControlEvents:UIControlEventTouchUpInside];
[_picBackImg addSubview:_cateSwich];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(title.frame) + 1, imgWid, 1)];
lineView.backgroundColor = RGB(242, 242, 242);
[_picBackImg addSubview:lineView];
_pic=[[UIPickerView alloc]initWithFrame:CGRectMake(10,CGRectGetMaxY(title.frame) + 2,imgWid - 20,imHeight -30 - 40- 20)];
_pic.dataSource=self;
_pic.delegate=self;
//_pic.backgroundColor = [UIColor blueColor];
[_picBackImg addSubview:_pic];
_sureBtn
=[UIButton buttonWithType:UIButtonTypeCustom];
_sureBtn.frame=CGRectMake(0, _picBackImg.frame.size.height - 44 + 3, _picBackImg.frame.size.width, 44);
_sureBtn.backgroundColor=COLOR_LABEL_TITLE;
[_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
_sureBtn.layer.masksToBounds=YES;
_sureBtn.layer.cornerRadius=8;
_sureBtn.userInteractionEnabled=YES;
[_picBackImg addSubview:_sureBtn];
[self dataSource];
_componentArray=[[NSMutableArray alloc] init];
UITapGestureRecognizer*tapgestureRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(XuToPicDismissAction:)];
[self addGestureRecognizer:tapgestureRecognizer];
}
-(void)XuToPicDismissAction:(UITapGestureRecognizer *)tapgestrue{
[self removeFromSuperview];
}
-(void)dataSource{
_picArr=@[@[@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50"]];
}
#pragma mark picView数据源
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
NSInteger component;
component=_picArr.count;
return component;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
NSArray *rowArray=[[NSArray alloc] init];
rowArray=_picArr[component];
return rowArray.count;
}
#pragma mark picView代理
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
NSString *rowTitle=nil;
rowTitle=_picArr[component][row];
_rowTitle=rowTitle;
return rowTitle;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSLog(@"**********4");
_component=component;
_row=row;
_picViewResultString=_picArr[0][row];
NSLog(@"_picViewResultString%@",_picViewResultString);
}
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
return pickerView.frame.size.height/5;;
}
-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
return pickerView.frame.size.width;
}
#pragma mark - 制冷制热
-(void)cateSwichAction:(UIButton *)btn{
if (_isCool) {
[_cateSwich setBackgroundImage:[UIImage imageNamed:@"window_heating"] forState:UIControlStateNormal];
}else{
[_cateSwich setBackgroundImage:[UIImage imageNamed:@"window_refrigeration"] forState:UIControlStateNormal];
}
if (self.wenDuPicviewDelegate) {
if (_isCool) {
//发送制热指令
[self.wenDuPicviewDelegate didSelectCoolOrHeat:@"00"];
}else{
//发送制冷指令
[self.wenDuPicviewDelegate didSelectCoolOrHeat:@"01"];
}
}
_isCool = !_isCool;
}
-(void)initCateBtnSate:(NSString*)hotCoolSate
{
if ([hotCoolSate isEqualToString:@"01"]) {
//制冷
[_cateSwich setBackgroundImage:[UIImage imageNamed:@"window_refrigeration"] forState:UIControlStateNormal];
_isCool = YES;
}else{
//制热
[_cateSwich setBackgroundImage:[UIImage imageNamed:@"window_heating"] forState:UIControlStateNormal];
_isCool = NO;
}
}
@end