我有一个带有JSON数据的UICollectionView。我想点击按钮时将GridView转换为List视图。怎么做?
答案 0 :(得分:0)
如果要更改为视图列表,则只需将单元格宽度设置为屏幕宽度或集合视图宽度 在从网格切换到列表视图时更新其值,如下所示,
在视图控制器中声明一个变量,如下所示
//Property to maintain cell size
@property CGFloat *listCellSize;
//Action methods
- (IBAction)listViewButtonPressed:(id)sender {
self.listCellSize = self.collectionView.frame.size.width;
[self.collecttionView reloadData];
}
- (IBAction)gridViewButtonPressed:(id)sender {
self.listCellSize = self.collectionView.frame.size.width / 3;
[self.collecttionView reloadData];
}
//CollectionView datasource method
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize cellSize = CGSizeMake(self.listCellSize, 100);
return cellSize;
}