// // remindCyclePic.m // Ifish // // Created by imac on 16/3/17. // Copyright © 2016年 imac. All rights reserved. // #import "remindCyclePic.h" #define CANCLE_BTN 100000100 #define SURE_BTN 100000120 @interface remindCyclePic() @end @implementation remindCyclePic -(instancetype)initWithFrame:(CGRect)frame{ self=[super initWithFrame:frame]; if (self) { [self initPic]; } return self; } -(void)initPic{ CGFloat imgWid= kScreenSize.width - 40*2; CGFloat imHeight= kScreenSize.width - 60; self.backgroundColor=[UIColor colorWithWhite:0 alpha:0.5]; _picBackImg =[[UIImageView alloc]initWithFrame:CGRectMake(40,kScreenSize.height/2-(kScreenSize.width -30)/2, imgWid, imHeight)]; _picBackImg.image=[UIImage imageNamed:@"Box"]; [self addSubview:_picBackImg]; _picBackImg.userInteractionEnabled=YES; UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, _picBackImg.frame.size.width-10*2, 20)]; title.text=@"换水天数选择"; title.textAlignment=NSTextAlignmentCenter; [_picBackImg addSubview:title]; _pic=[[UIPickerView alloc]initWithFrame:CGRectMake(10,title.frame.origin.y + 20,imgWid - 20,imHeight -30 - 40- 20)]; _pic.dataSource=self; _pic.delegate=self; [_picBackImg addSubview:_pic]; _cancleBtn=[UIButton buttonWithType:UIButtonTypeCustom]; _cancleBtn.backgroundColor=[UIColor lightGrayColor]; CGFloat wdspace=40; _cancleBtn.frame=CGRectMake(40,_pic.frame.origin.y + _pic.frame.size.height - 10, (_picBackImg.frame.size.width-3*wdspace)/2, 30); [_cancleBtn setTitle:@" 取消" forState:UIControlStateNormal]; _cancleBtn.layer.masksToBounds=YES; _cancleBtn.layer.cornerRadius=8; _cancleBtn.userInteractionEnabled=YES; _cancleBtn.tag=CANCLE_BTN; //[_picBackImg addSubview:_cancleBtn]; _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; _sureBtn.tag=SURE_BTN; [_picBackImg addSubview:_sureBtn]; [self dataSource]; UITapGestureRecognizer *sigleTap=[[UITapGestureRecognizer alloc] init ]; [self addGestureRecognizer:sigleTap]; CGPoint locationP= [sigleTap locationInView:self]; BOOL isIn= CGRectContainsPoint( _picBackImg.frame ,locationP); if (!isIn) { [sigleTap addTarget:self action:@selector(dissmissView)]; } _componentArray=[[NSMutableArray alloc] init]; } -(void)dissmissView{ [self removeFromSuperview]; } -(void)dataSource{ _picArr=@[@[@"1",@"2",@"3",@"4",@"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]; // if (![self.componentArray containsObject:@(component)]) { // [self.componentArray addObject:@(component)]; // } // for (int i=0; i<_picArr.count;i++) { // if ([self.componentArray containsObject:@(i)]) { // NSInteger cIndex = [pickerView selectedRowInComponent:i]; // // // _picViewResultString=[NSString stringWithFormat:@"%@%@",_picViewResultString,_picArr[i][cIndex]]; // // }else{ // // NSLog(@"%ld",(long)_heighindex); // if (i==0) { // _picViewResultString=[NSString stringWithFormat:@"%@%@",_picViewResultString ,_picArr[i][_lowindex]]; // }else if (i==1) { // _picViewResultString=[NSString stringWithFormat:@"%@%@",_picViewResultString ,_picArr[i][0]]; // }else if (i==2){ // _picViewResultString=[NSString stringWithFormat:@"%@%@",_picViewResultString ,_picArr[i][_heighindex]]; // } // // } // } 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; } @end