Ios 根据UILabel大小展开UILabel和UICollectionView单元格

Ios 根据UILabel大小展开UILabel和UICollectionView单元格,ios,objective-c,uicollectionview,uilabel,Ios,Objective C,Uicollectionview,Uilabel,我有以下UICollectionView设置: 上面写着“漂亮”的是一个标签。目前,如果文本超出标签的大小,我会截断它 是否有方法垂直扩展UILabel和CollectionViewCell以适应所有文本 谢谢大家! 编辑: 到目前为止,我已经实施了: -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

我有以下UICollectionView设置:

上面写着“漂亮”的是一个标签。目前,如果文本超出标签的大小,我会截断它

是否有方法垂直扩展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
}

像这样设置单元格的约束

  • 第一个标签:顶部、左侧、右侧、底部至图像。(如果这只是一条直线,则高度也是如此)
  • 图像:(中心,宽度)或(左,右)和高度,从下到第二个标签
  • 第二标签: 左对齐,右对齐到图像,numberOfLines=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;
}

你能在这里发布到目前为止在CollectionViewCell中实现的内容吗?@IOSENTUSIATIC DONEI如果你使用过自动布局,那么发布一个屏幕截图。@IOSENTUSIATIC刚刚做过。如果你的约束条件合适,你有没有试过使用flowLayout.estimatedItemSize=cSizeMake(宽度,高度),通过查看布局,希望你已经设置了第一个标签的固定高度,然后是图像和底部按钮。只有第二个标签的高度不固定,numberOfLiinesTo=0