调整集合视图单元格大小

时间:2016-02-23 17:52:04

标签: uicollectionview uicollectionviewcell

我在一个视图控制器上有2个集合视图。 我希望细胞调整高度和高度。宽度到集合视图的高度。

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  float cellHeight = 0;
  float cellWidth = 0;
     if (collectionView == self.channelsCollectionView) {

cellHeight = self.channelsCollectionView.collectionViewLayout.collectionViewContentSize.height;
cellWidth = cellHeight ;
 }
  if (collectionView == self.favoritesCollectionView){
cellHeight = self.favoritesCollectionView.collectionViewLayout.collectionViewContentSize    .height;
cellWidth = cellHeight ;

 }

 return CGSizeMake(cellHeight, cellWidth);
}

2 个答案:

答案 0 :(得分:1)

试试这个

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  float cellHeight = 0;
  float cellWidth = 0;
     if (collectionView == self.channelsCollectionView) {

cellHeight = self.channelsCollectionView.frame.size.height;
cellWidth = cellHeight ;
 }
  if (collectionView == self.favoritesCollectionView){
cellHeight = self.favoritesCollectionView.frame.size.height;
cellWidth = cellHeight ;

 }

 return CGSizeMake(cellHeight, cellWidth);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  float cellHeight = collectionView.frame.size.height;
  return CGSizeMake(cellHeight, cellHeight);
}

答案 1 :(得分:0)

您可以通过提供集合视图标记

来管理它
.hide-similar .similar1 {
    display: none;
}