2017-01-17 4 views
7

내가 내 응용 프로그램UICollectionView 동적 셀 높이 (대표자 : 레이아웃)

Pinterest 레이아웃을 달성하기 위해 노력하고있어 나는 그것을 달성하고 셀 높이를 설정하려면 다음 대리자 메서드를 사용하여 동적으로

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
    let boundingRect = CGRect(x: 0, y: 0, width: self.view.frame.size.width/2 - 20, height: CGFloat(MAXFLOAT)) 
    let data = articles[indexPath.row] 
    let rect = AVMakeRect(aspectRatio: (data.coverImage?.size)!, insideRect: boundingRect) 
    return CGSize(width: rect.width, height: rect.height + 120) // Added 120 for a description I will add later 
} 

그러나

Here

회색 배경 셀의 배경, 당신은 일을 볼 수 있습니다 나는 다음과 같은 결과를 얻었다 각 셀에는 (높이 예상대로) 자체 높이가 있지만 제거 방법을 모르는 여분의 공백이 있습니다.

어떻게 해결할 수 있습니까?

+0

아무도 시도하지 않았습니까? 왜 대답이 없습니까? – adev

답변

0

UICollectionView 레이아웃이 올바르지 않습니다. 스토리 보드 또는 CollectionViewDelegateFlowLayout 방법을 통해 셀 간격과 열 간격을 제거합니다.

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { 
    return CGFloat()// Your Value 
} 

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { 
    return CGFloat()// Your Value 
    }