美文网首页
网格视图

网格视图

作者: 繁华落尽终是殇 | 来源:发表于2017-11-23 11:17 被阅读0次

#pragma mark - 网格视图

- (UICollectionView *)collections{

if (!_collections) {

_collections = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 230, self.view.frame.size.width, 300) collectionViewLayout:self.flow];

[_collections setDelegate:self];

[_collections setDataSource:self];

[_collections setBackgroundColor:[UIColor whiteColor]];

[_collections registerClass:[myCollectionViewCell class] forCellWithReuseIdentifier:@"myCell"];

}

return _collections;

}

- (UICollectionViewFlowLayout *)flow{

if (!_flow) {

_flow = [[UICollectionViewFlowLayout alloc]init];

[_flow setItemSize:CGSizeMake(80, 80)];

[_flow setMinimumLineSpacing:15];

[_flow setMinimumInteritemSpacing:10];

}

return _flow;

}

#pragma mark - 网格视图的 delegate datasour

- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

return 1;

}

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

return 12;

}

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

myCollectionViewCell *mycell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];

//[mycell setBackgroundColor:[UIColor redColor]];

mycell.theimageview.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld",indexPath.item]];

mycell.thelable.text = [NSString stringWithFormat:@"%@",ziarray[indexPath.row]];

return mycell;

}

相关文章

网友评论

      本文标题:网格视图

      本文链接:https://www.haomeiwen.com/subject/knxzvxtx.html