我需要只有简单的UICollectionViewCell样式与每个顶部的单元格。像tableview一样。但我需要动态高度依赖的内容,大小内容是评论它可以变化。如何从其内容设置动态uicollectionviewcell大小 - 以编程方式
我 viewDidLoad中:
[self.commentsCollectionView registerClass:[GWCommentsCollectionViewCell class] forCellWithReuseIdentifier:@"commentCell"];
在.H我:
,我#IMPORT我的自定义UICollectionViewCell,设置与编程自动布局所有约束。
我实例与UICollectionView:
UICollectionViewFlowLayout *collViewLayout = [[UICollectionViewFlowLayout alloc]init];
self.commentsCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:collViewLayout];
我用autolatyout得到UICollectionView是,我想(这就是为什么CGRectZero)。
最后,我希望能做到这一点:
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
GWCommentsCollectionViewCell *cell = (GWCommentsCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
return cell.singleCommentContainerview.bounds.size;
}
singleCommentContainerview是内容查看的直接子视图和withing的singleCommentContainerview我有UILabels,UIImageViews的等,都设置witih autolayoutcode。
但我刚刚得到的(0,0)
cgsize值我怎样才能解决这个问题得到适当的大小,我需要为每个单元?
我有一个完整的解决方案即将推出,上面是不对的! – elliotrock