欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS仿Uber筛选栏效果

程序员文章站 2024-02-16 20:00:13
这个是之前项目中用的仿uber筛选栏,现在要改了,改之前把这个记录下来,万一有人用到了,就可以直接拿来用了,这个是在大神的基础上改的,还行吧,但是觉得有点丑!有需要的可以看...

这个是之前项目中用的仿uber筛选栏,现在要改了,改之前把这个记录下来,万一有人用到了,就可以直接拿来用了,这个是在大神的基础上改的,还行吧,但是觉得有点丑!有需要的可以看一下,方法有点笨,大神勿喷。

iOS仿Uber筛选栏效果

iOS仿Uber筛选栏效果

1.加载数据

 * 加载数据
 */
- (void)loaddata{
 timearray = @[@"6小时之内",@"12小时之内",@"24小时之内"];
 locationarray = @[@"全城",@"附近1km",@"附近3千米",@"附近5千米",@"附近10千米"];
 picearray = @[@"价格不限",@"0-5元",@"5-20元",@"20-50元",@"50-100元"];

}

2.加载视图

 * 加载ui视图
 */
-(void)shuaxin{

 dicengbackeview = [[uiview alloc]initwithframe:cgrectmake(0, kscreenheight-140, kscreenwidth, 420)];

 dicengbackeview.backgroundcolor = [uicolor colorwithwhite:0.850 alpha:1.000];

 [self.view addsubview:dicengbackeview];

 filter = [[sefiltercontrollist alloc]initwithframe:cgrectmake((kscreenwidth-300)/2, -5, 300, 30) titles:[nsarray arraywithobjects:@"时间", @"附近", @"价格",nil]];

 filter.userinteractionenabled = yes;

 [filter addtarget:self action:@selector(filtervaluechanged:) forcontrolevents:uicontroleventtouchupinside];

 [filter setprogresscolor:[uicolor grouptableviewbackgroundcolor]];//设置滑杆的颜色

 [filter settitlesfont:[uifont fontwithname:@"didot" size:16]];

 [filter settoptitlescolor:[uicolor blackcolor]];//设置滑块上方字体颜色

 [filter setselectedindex:0];//设置当前选中

 [dicengbackeview addsubview:filter];


 button_uiview = [[uiview alloc]initwithframe:cgrectmake(0, 70,kscreenwidth,240)];

 button_uiview.backgroundcolor = [uicolor colorwithwhite:0.730 alpha:1.000];

 [dicengbackeview addsubview:button_uiview];

 _backsrollview = [[uiscrollview alloc]initwithframe:cgrectmake(0, 0,kscreenwidth , 240)];

 _backsrollview.pagingenabled = yes;

 _backsrollview.userinteractionenabled = yes;

 _backsrollview.contentsize =cgsizemake(kscreenwidth*3, 0);
 //设置是否滚动
 _backsrollview.scrollenabled = no;

 [button_uiview addsubview:_backsrollview];

 imageview1 = [[uiimageview alloc]initwithframe:cgrectmake(0, 0, kscreenwidth, _backsrollview.frame.size.height)];

 imageview2 = [[uiimageview alloc]initwithframe:cgrectmake(kscreenwidth, 0, kscreenwidth, _backsrollview.frame.size.height)];

 imageview3 = [[uiimageview alloc]initwithframe:cgrectmake(kscreenwidth*2, 0, kscreenwidth, _backsrollview.frame.size.height)];
#pragma mark ==========loading===================
 imageview1.userinteractionenabled = yes;

 imageview2.userinteractionenabled = yes;

 imageview3.userinteractionenabled = yes;

#pragma mark ==========loading===================
 for (int g =0; g<3; g++) {

  uibutton *button1 = [uibutton buttonwithtype:uibuttontypecustom];

  button1.frame = cgrectmake(0, (180/3)*g, kscreenwidth, 180/3);
  button1.backgroundcolor = [uicolor colorwithwhite:0.850 alpha:1.000];

  [button1 settitle:timearray[g] forstate:uicontrolstatenormal];

  [button1 settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal];

  button1.tag = 100+g;

  button1.titlelabel.textalignment = nstextalignmentcenter;

  button1.layer.bordercolor = [[uicolor colorwithwhite:0.837 alpha:1.000] cgcolor];

  button1.layer.borderwidth = 1.0f;

  [button1 addtarget:self action:@selector(timebtn:) forcontrolevents:uicontroleventtouchupinside];

  [imageview1 addsubview:button1];

 }

 for (int k =0; k<5; k++) {

  uibutton *button2 = [uibutton buttonwithtype:uibuttontypecustom];

  button2.frame = cgrectmake(0, (180/5)*k, kscreenwidth, 180/5);
  button2.backgroundcolor = [uicolor colorwithwhite:0.850 alpha:1.000];

  [button2 settitle:locationarray[k] forstate:uicontrolstatenormal];

  [button2 settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal];

  button2.tag = 200+k;

  button2.titlelabel.textalignment = nstextalignmentcenter;

  button2.layer.bordercolor = [[uicolor colorwithwhite:0.837 alpha:1.000] cgcolor];

  button2.layer.borderwidth = 1.0f;

  [imageview2 addsubview:button2];

  [button2 addtarget:self action:@selector(timebtn:) forcontrolevents:uicontroleventtouchupinside];

 }

 for (int y =0; y<5; y++) {

  uibutton *button3 = [uibutton buttonwithtype:uibuttontypecustom];

  button3.frame = cgrectmake(0, (180/5)*y, kscreenwidth, 180/5);

  button3.backgroundcolor = [uicolor colorwithwhite:0.850 alpha:1.000];

  [button3 settitle:picearray[y] forstate:uicontrolstatenormal];

  [button3 settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal];

  button3.tag = 300+y;

  button3.titlelabel.textalignment = nstextalignmentcenter;

  button3.layer.bordercolor = [[uicolor colorwithwhite:0.837 alpha:1.000] cgcolor];

  button3.layer.borderwidth = 1.0f;

  [imageview3 addsubview:button3];

  [button3 addtarget:self action:@selector(timebtn:) forcontrolevents:uicontroleventtouchupinside];
 }

 [_backsrollview addsubview:imageview1];

 [_backsrollview addsubview:imageview2];

 [_backsrollview addsubview:imageview3];

}

- (void)filtervaluechanged:(sefiltercontrollist *)sender{

 nslog(@"%d",sender.selectedindex);
 switch (sender.selectedindex) {
  case 0:{

   break;
  }
  case 1:{

   break;
  }
  case 2:{

   break;
  }
  default:
   break;
 }

 _backsrollview.contentoffset = cgpointmake([sender selectedindex]*kscreenwidth, 0);

// self.table.contentinset = uiedgeinsetsmake(0, 0, 230, 0);

 [uiview animatewithduration:0.2 animations:^{


  [uiview animatewithduration:0.2 animations:^{

   dicengbackeview.frame = cgrectmake(0,kscreenheight-310 , kscreenwidth,310);
  }];


 } completion:^(bool finished) {

 }];

}


- (void)timebtn:(uibutton *)sender{

 switch (sender.tag) {
  case 100:{

   [shaixuan setobject:@"6" forkey:@"times"];

   [self dianji];
   [self chuanzhi];

   break;
  }
  case 101:{



   [shaixuan setobject:@"12" forkey:@"times"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];
   break;
  }
  case 102:{

   [shaixuan setobject:@"24" forkey:@"times"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];
   break;
  }

  case 200:{


   [shaixuan setobject:@"0" forkey:@"nearby"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }

  case 201:{



   [shaixuan setobject:@"1" forkey:@"nearby"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }

  case 202:{



   [shaixuan setobject:@"3" forkey:@"nearby"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }


  case 203:{



   [shaixuan setobject:@"5" forkey:@"nearby"];

   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }


  case 204:{



   [shaixuan setobject:@"10" forkey:@"nearby"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }

  case 300:{



   [shaixuan setobject:@"0" forkey:@"pricenumber"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }
  case 301:{



   [shaixuan setobject:@"1" forkey:@"pricenumber"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];
   break;
  }
  case 302:{



   [shaixuan setobject:@"2" forkey:@"pricenumber"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }
  case 303:{

   [shaixuan setobject:@"3" forkey:@"pricenumber"];

   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }
  case 304:{

   [shaixuan setobject:@"4" forkey:@"pricenumber"];


   [self dianji];
   //   [self pianyi];
   [self chuanzhi];

   break;
  }
  default:
   break;
 }
#pragma mark ===================

}


-(void)dianji{


 [uiview animatewithduration:0.2 animations:^{

  dicengbackeview.frame = cgrectmake(0, kscreenheight-135, kscreenwidth, 370);
 }];
}
//将参数传给后台,请求数据
-(void)chuanzhi{


}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。