我通过以下方式设置了UICollectionView:
它说“漂亮”的地方是UILabel。目前,如果文本超出标签的大小,我会截断文本。
有没有办法垂直扩展UILabel和CollectionViewCell以适应所有文本?
谢谢!
编辑:
到目前为止我已实施的内容:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionViewCellimage *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"birthdayCollView" forIndexPath:indexPath];
PhotoClass *photoClass = [arrBirthdayPhotos objectAtIndex:indexPath.row];
cell.lblDescription.text = photoClass.description;
// same implementation for other fields
}
答案 0 :(得分:0)
像这样设置单元格的约束。
然后在视图控制器中为collectionView设置 estimatedItemSize 。
//Set CollectionView Layout
[self.collectionView setCollectionViewLayout:self.flowLayout];
self.flowLayout.estimatedItemSize = CGSizeMake(width, height);
-(UICollectionViewFlowLayout *)flowLayout{
if(!_flowLayout) {
_flowLayout = [[UICollectionViewFlowLayout alloc] init];
[_flowLayout setSectionInset:UIEdgeInsetsMake(topSpacing, leftMargin, bottomSpacing, rightMargin)];
[_flowLayout setMinimumInteritemSpacing:cellSpacing];
[_flowLayout setMinimumLineSpacing:lineSpacing];
[_flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
}
return _flowLayout;
}