iOS购物分类模块的实现方案

2020-01-14 20:04:58丽君

实现文件中: 


- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
     
   
  UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(searchBarButtonItemAction)];
  self.navigationItem.rightBarButtonItem = searchBarButtonItem;
    [self setdata];
  [self setimage];
  [self setdeatil];
   
     
  _a=1;
  _b=1;
  _segement=[[UISegmentedControl alloc]initWithItems:@[@"攻略",@"详情"]];
  _segement.frame=CGRectMake(90, 20, kwidth-180, 30);
  _segement.tintColor=[UIColor blackColor];
  _segement.selectedSegmentIndex=0;
  [_segement addTarget:self action:@selector(changevalue:) forControlEvents:(UIControlEventValueChanged)];
  self.navigationItem.titleView =_segement;
   self.scrollview=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kwidth, KHeight)];
  _scrollview.directionalLockEnabled=YES;
  _scrollview.contentSize=CGSizeMake(kwidth*2, KHeight);
  _scrollview.delegate=self;
     
     
  [self.view addSubview:self.scrollview];
  UICollectionViewFlowLayout*flow=[[UICollectionViewFlowLayout alloc]init];
    //列距
  flow.minimumInteritemSpacing=20;
     
  //行距
  flow.minimumLineSpacing=40;
    //分区内边距
  flow.sectionInset=UIEdgeInsetsMake(0, 20, 20, 20);
    CGFloat totalwidth=self.view.frame.size.width;
     
  CGFloat itemwidth=(totalwidth-2*20-3*20)/4.0;
     
  CGFloat itemheight=itemwidth;
     
  flow.itemSize=CGSizeMake(itemwidth, itemheight);
     
  flow.headerReferenceSize=CGSizeMake(0, 40);
     
  //滚动方向
  flow.scrollDirection= UICollectionViewScrollDirectionVertical;
  ;
     
  //区头大小
  flow.headerReferenceSize=CGSizeMake(0, 100);
     
  _collection=[[UICollectionView alloc]initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flow];
  _collection.backgroundColor=[UIColor whiteColor];
  _collection.tag=1;
  _Srr=@[@"1",@"s",@"2",@"r"];
  for (NSString*St in _Srr) {
    [_collection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:St];}
  //设置 数据源 和代理
  _collection.dataSource=self;
  _collection.delegate=self;
  [_collection registerClass:[ClassCollectionViewCell class] forCellWithReuseIdentifier:@"mycell"];
  // _collection.backgroundColor=[UIColor yellowColor];
  _collection.directionalLockEnabled=YES;
     
  [self.scrollview addSubview:_collection];
  UIView*view=[[UIView alloc]initWithFrame:CGRectMake(kwidth, 0, kwidth, 30)];
  // view.backgroundColor = [UIColor whiteColor];
  UIButton*label=[UIButton buttonWithType:(UIButtonTypeSystem)];
  label.frame=CGRectMake(0, 20, 200, 14) ;
  [label setTitle:@"选礼神器" forState:(UIControlStateNormal)];
  [label addTarget:self action:@selector(xuan) forControlEvents:(UIControlEventTouchUpInside)];
  [view addSubview:label];
  [self.scrollview addSubview:view];