353 lines
11 KiB
Objective-C
353 lines
11 KiB
Objective-C
//
|
|
// FourControlViewController.m
|
|
// Ifish
|
|
//
|
|
// Created by imac on 16/4/5.
|
|
// Copyright © 2016年 imac. All rights reserved.
|
|
//
|
|
|
|
#import "FourControlViewController.h"
|
|
|
|
#import "FourControlCanChangeImgController.h"
|
|
#import "UIButton+WebCache.h"
|
|
#import "FourControlSetViewController.h"
|
|
#define FOURCONTROL_LIGR1TAG 221
|
|
#define FOURCONTROL_LIGR2TAG 222
|
|
#define FOURCONTROL_LIGR3TAG 223
|
|
#define FOURCONTROL_PUMPTAG 224
|
|
//四控 八十五字节
|
|
@interface FourControlViewController ()
|
|
|
|
@property(nonatomic,strong)FourControlCanChangeImgController *fourControlVC;
|
|
|
|
@property(nonatomic,strong)FourControlSetViewController *forControlSetVC;
|
|
|
|
|
|
|
|
@end
|
|
|
|
@implementation FourControlViewController
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
//点击设置界面返回按钮时 更换主界面 控制按钮图片
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(imagevchange:) name:@"CHANGE_IMGE" object:self.currentDevice];
|
|
//主界面按钮事件分离
|
|
|
|
[self.SetTimeButton addTarget:self action:@selector(fourControlSetBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
[self.setbackBtn addTarget:self action:@selector(fourControlSetBtnAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
UITapGestureRecognizer*tapgestureRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(fourCenterViewSetTap)];
|
|
[self.setImag addGestureRecognizer:tapgestureRecognizer];
|
|
|
|
UITapGestureRecognizer*tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(fourControlViewclockViewClick)];
|
|
self.clockView.userInteractionEnabled=YES;
|
|
[self.clockView addGestureRecognizer:tapGesture];
|
|
[self initFourControlBtn];
|
|
|
|
}
|
|
|
|
#pragma mark - 两控界面设置btn点击事件
|
|
|
|
-(void)fourControlSetBtnAction:(UIButton*)btn{
|
|
|
|
NSLog(@"点击了设置");
|
|
[self pushSetTimeVC];
|
|
|
|
}
|
|
|
|
#pragma mark - 设置图片点击事件
|
|
|
|
-(void)fourCenterViewSetTap{
|
|
|
|
NSLog(@"点击了图片");
|
|
[self pushSetTimeVC];
|
|
}
|
|
|
|
#pragma mark - 锁屏图片点击事件
|
|
|
|
-(void)fourControlViewclockViewClick{
|
|
|
|
[self pushSetTimeVC];
|
|
}
|
|
|
|
#pragma mark - 转跳设置界面
|
|
|
|
-(void)pushSetTimeVC{
|
|
|
|
_fourControlVC=[[FourControlCanChangeImgController alloc]init];
|
|
|
|
[self.navigationController pushViewController:_fourControlVC animated:YES];
|
|
// self.navigationBarHidden=NO;
|
|
|
|
}
|
|
|
|
|
|
#pragma mark - 四控按钮初始化
|
|
|
|
-(void)initFourControlBtn{
|
|
|
|
if (self.button) {
|
|
self.button=nil;
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断 是否自定意图标
|
|
|
|
NSMutableArray*buttonBackImges=[[NSMutableArray alloc] init];
|
|
NSArray *strArr=[[NSArray alloc] init];
|
|
NSArray*namearry=[[NSArray alloc] init];
|
|
NSArray*allIconNameArr=[[NSArray alloc] init];
|
|
// 判断是否有自定义图标
|
|
if ([self.currentDevice.isCustomIcon isEqualToString:@"1"]) {
|
|
|
|
|
|
if (![self.currentDevice.customIconName isEqualToString:@""]) {
|
|
//图片url
|
|
|
|
strArr = [self.currentDevice.customIconName componentsSeparatedByString:@","];
|
|
|
|
allIconNameArr =[self.currentDevice.allIconName componentsSeparatedByString:@","];
|
|
|
|
|
|
for (int i = 0 ; i <strArr.count ; i ++) {
|
|
int index=[strArr[i] intValue];
|
|
NSString *picUrl = [NSString stringWithFormat:@"%@%@",self.currentDevice.iconLink,allIconNameArr[index]];
|
|
[buttonBackImges addObject:picUrl];
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
strArr=[self.currentDevice.defaultIconName componentsSeparatedByString:@","];
|
|
|
|
|
|
for (int i = 0 ; i <strArr.count ; i ++) {
|
|
int index=[strArr[i] intValue];
|
|
|
|
allIconNameArr =[self.currentDevice.allIconName componentsSeparatedByString:@","];
|
|
|
|
NSString *picUrl = [NSString stringWithFormat:@"%@%@",self.currentDevice.iconLink,allIconNameArr[index]];
|
|
|
|
[buttonBackImges addObject:picUrl];
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//图片名
|
|
|
|
if (![self.currentDevice.customShowName isEqualToString:@""]) {
|
|
namearry=[self.currentDevice.customShowName componentsSeparatedByString:@","];
|
|
}else{
|
|
|
|
//无自定义图标名 选择默认
|
|
namearry= [self.currentDevice.defaultShowName componentsSeparatedByString:@","];
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
//无自定义图标 默认
|
|
strArr=@[@"PFLight1_off.png",@"PFLight1_off.png",@"PFLight1_off.png",@"ChongLang_off.png"];
|
|
|
|
namearry= @[@"灯1",@"灯2",@"灯3",@"UV/冲浪"];
|
|
|
|
|
|
}
|
|
|
|
// 设置button
|
|
|
|
|
|
CGFloat wspace=25;
|
|
CGFloat btnwidth= (kScreenSize.width-wspace * 5)/4;
|
|
for (int i = 0; i < strArr.count; i++) {
|
|
|
|
self.button=[UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
self.button.layer.masksToBounds=YES;
|
|
|
|
self.button.layer.cornerRadius=8;
|
|
self.button.tag=221+i;
|
|
self.button.frame=CGRectMake((wspace+i * (btnwidth+wspace)), (kScreenSize.height -180 ),btnwidth, btnwidth);
|
|
if ([self.currentDevice.isCustomIcon isEqualToString:@"1"]) {
|
|
//可自定义图标走网络请求
|
|
[self.button sd_setBackgroundImageWithURL:[NSURL URLWithString:buttonBackImges[i]] forState:UIControlStateNormal];
|
|
|
|
}else{
|
|
// 不可自定义图标 加载本地图片
|
|
[self.button setImage:[UIImage imageNamed:strArr[i]] forState:UIControlStateNormal];
|
|
|
|
}
|
|
|
|
if (i==0) {
|
|
_light1Button = self.button;
|
|
|
|
}else if (i==1){
|
|
|
|
_light2Button = self.button;
|
|
}else if (i==2){
|
|
|
|
_light3Button = self.button;
|
|
|
|
}else if (i==3){
|
|
|
|
_pumpButton = self.button;
|
|
}
|
|
|
|
|
|
[self.tableView addSubview:self.button];
|
|
|
|
}
|
|
|
|
// 设置label
|
|
|
|
for (int j = 0; j<strArr.count; j++) {
|
|
self.buttonNameLabel=[[UILabel alloc]initWithFrame:CGRectMake((wspace+j * (btnwidth+wspace)),(kScreenSize.height-180+btnwidth),btnwidth, 20)];
|
|
//self.buttonNameLabel.text = namearry[j];
|
|
self.buttonNameLabel.font = [UIFont systemFontOfSize:13];
|
|
self.buttonNameLabel.textColor = COLOR_LABEL_TITLE;
|
|
self.buttonNameLabel.textAlignment = NSTextAlignmentCenter;
|
|
self.buttonNameLabel.tag=230 + j;
|
|
|
|
self.buttonNameLabel.text = namearry[j];
|
|
|
|
if (j==0) {
|
|
_light1name=self.buttonNameLabel;
|
|
|
|
}else if (j==1){
|
|
|
|
_light2name=self.buttonNameLabel;
|
|
|
|
}else if (j==2){
|
|
|
|
_light3name = self.buttonNameLabel;
|
|
|
|
}else if (j==3){
|
|
|
|
_pumpname = self.buttonNameLabel;
|
|
|
|
}
|
|
|
|
[self.tableView addSubview:self.buttonNameLabel];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-(void)imagevchange:(NSNotification*)info{
|
|
|
|
NSLog(@"%@",info);
|
|
// [self initFourControlBtn];
|
|
[self resetButtonImage];
|
|
|
|
|
|
}
|
|
|
|
#pragma mark 重置 自定义图标 按钮图片
|
|
|
|
-(void)resetButtonImage{
|
|
|
|
//判断 是否自定意图标
|
|
|
|
NSMutableArray*buttonBackImges=[[NSMutableArray alloc] init];
|
|
NSArray *strArr=[[NSArray alloc] init];
|
|
NSArray*namearry=[[NSArray alloc] init];
|
|
NSArray*allIconNameArr=[[NSArray alloc] init];
|
|
// 判断是否有自定义图标
|
|
if ([self.currentDevice.isCustomIcon isEqualToString:@"1"]) {
|
|
|
|
if (![self.currentDevice.customIconName isEqualToString:@""]) {
|
|
//图片url
|
|
|
|
strArr = [self.currentDevice.customIconName componentsSeparatedByString:@","];
|
|
|
|
allIconNameArr =[self.currentDevice.allIconName componentsSeparatedByString:@","];
|
|
|
|
|
|
for (int i = 0 ; i <strArr.count ; i ++) {
|
|
int index=[strArr[i] intValue];
|
|
NSString *picUrl = [NSString stringWithFormat:@"%@%@",self.currentDevice.iconLink,allIconNameArr[index]];
|
|
[buttonBackImges addObject:picUrl];
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
strArr=[self.currentDevice.defaultIconName componentsSeparatedByString:@","];
|
|
|
|
for (int i = 0 ; i <strArr.count ; i ++) {
|
|
int index=[strArr[i] intValue];
|
|
|
|
allIconNameArr =[self.currentDevice.allIconName componentsSeparatedByString:@","];
|
|
|
|
NSString *picUrl = [NSString stringWithFormat:@"%@%@",self.currentDevice.iconLink,allIconNameArr[index]];
|
|
|
|
[buttonBackImges addObject:picUrl];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//图片名
|
|
|
|
if (![self.currentDevice.customShowName isEqualToString:@""]) {
|
|
namearry=[self.currentDevice.customShowName componentsSeparatedByString:@","];
|
|
}else{
|
|
|
|
//无自定义图标名 选择默认
|
|
namearry= [self.currentDevice.defaultShowName componentsSeparatedByString:@","];
|
|
}
|
|
|
|
|
|
}else{
|
|
|
|
//无自定义图标 默认
|
|
strArr=@[@"lightclose.png",@"lightclose.png",@"lightclose.png",@"pumpclose.png"];
|
|
|
|
namearry= @[@"灯1",@"灯2",@"灯3",@"UV/冲浪"];
|
|
|
|
}
|
|
|
|
// 设置button
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
//可自定义图标走网络请求
|
|
NSLog(@"strarr%@",strArr);
|
|
[_light1Button sd_setBackgroundImageWithURL:[NSURL URLWithString:buttonBackImges[0]] forState:UIControlStateNormal];
|
|
|
|
[_light2Button sd_setBackgroundImageWithURL:[NSURL URLWithString:buttonBackImges[1]] forState:UIControlStateNormal];
|
|
|
|
[_light3Button sd_setBackgroundImageWithURL:[NSURL URLWithString:buttonBackImges[2]] forState:UIControlStateNormal];
|
|
|
|
[_pumpButton sd_setBackgroundImageWithURL:[NSURL URLWithString:buttonBackImges[3]] forState:UIControlStateNormal];
|
|
|
|
_light1name.text=namearry[0];
|
|
_light2name.text=namearry[1];
|
|
_light3name.text=namearry[2];
|
|
_pumpname.text=namearry[3];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
|
|
}
|
|
|
|
|
|
@end
|