网格的布局

2018-11-22  本文已影响0人  傻人有傻福i

@interface QBViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>{

    UICollectionViewFlowLayout *flowLayout;

    UICollectionView *cv;

}

staticNSString*oj =@"cell";

  // 创建流水布局

    flowLayout = [[UICollectionViewFlowLayout alloc]init];

    // 设置网格大小

    flowLayout.itemSize = CGSizeMake((self.view.frame.size.width-10)/2, 320);

    // 设置最小行间距

    flowLayout.minimumLineSpacing = 0;

    // 设置最小列间距

    flowLayout.minimumInteritemSpacing = 0;

    // 创建网格

    cv = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flowLayout];

    // 设置代理

    cv.delegate=self;

    cv.dataSource = self;

    // 设置网格背景颜色

    cv.backgroundColor = [UIColor whiteColor];

    // 注册cell

    [cv registerClass:[YZGMJCollectionViewCell class] forCellWithReuseIdentifier:oj];

    [self.view addSubview:cv];

}

// 设置网格个数

-(NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section{

    return 0;

}

-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{

    YZGMJCollectionViewCell * cell=[cv dequeueReusableCellWithReuseIdentifier:oj forIndexPath:indexPath];

    JDModel* model=[JDModelnew];

    cell.imgv.image=[UIImageimageNamed:model.imgv[indexPath.row]];

    cell.lb1.text=model.lable1[indexPath.row];

    cell.lb2.text=model.lable2[indexPath.row];

    return cell;

}

-(void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath{

    self.hidesBottomBarWhenPushed = YES;

    twoViewController *fl = [twoViewController new];

    [self.navigationController pushViewController:fl animated:YES];

    self.hidesBottomBarWhenPushed = NO;

}

-(void)viewWillAppear:(BOOL)animated{

    self.navigationController.navigationBar.hidden = NO;

}

上一篇 下一篇

猜你喜欢

热点阅读