각 셀 상단에 셀이있는 간단한 UICollectionViewCell 스타일이 필요합니다. tableview와 같습니다. 하지만 콘텐츠의 동적 높이 의존성, 콘텐츠의 크기가 달라질 수 있습니다. 내가 가진콘텐츠에서 동적 uicollectionviewcell 크기를 설정하는 방법 - 프로그래밍 방식으로
[self.commentsCollectionView registerClass:[GWCommentsCollectionViewCell class] forCellWithReuseIdentifier:@"commentCell"];
.H에서 :
나는 # import를 내 사용자 지정 UICollectionViewCell 프로그램 자동 레이아웃 모든 제약 조건을 설정
나는 의 viewDidLoad을 얻었다.UICollectionViewFlowLayout *collViewLayout = [[UICollectionViewFlowLayout alloc]init];
self.commentsCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:collViewLayout];
은 내가 (그게 왜 CGRectZero를) 할 위치를 UICollectionView 될 얻을 autolatyout를 사용
내가 가진 UICollectionView를 인스턴스화합니다.
그리고 마지막으로 내가이 일을 기대했다 :
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
GWCommentsCollectionViewCell *cell = (GWCommentsCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
return cell.singleCommentContainerview.bounds.size;
}
singleCommentContainerview 모든 autolayoutcode 패널 컴퓨터 설정 직접있는 contentView의 서브 뷰와 withing에 내가 UIImageViews 등 UILabels을 가지고있는 singleCommentContainerview입니다.
하지만 단지 (0,0)
의 cgsize의 가치를 어떻게 이것이 내가 각 셀에 필요한 적절한 크기를 얻을 해결할 수 있습니까?
나는 완벽한 솔루션을 곧 제공 할 예정입니다. – elliotrock