[英]UICollectionView Wrap Cell around Label
我需要能够围绕Label包装UICollectionViewCell(带有一些填充)。 基本上,我正在寻找这样的东西(这是在Android上完成的,没有太多麻烦):
这是我到目前为止在我的UICollectionView中所拥有的。 每个单元格是一个设置宽度(屏幕宽度/ 3),但最后我希望每个单元格都是标签的宽度(+一些额外的填充):
我试过覆盖sizeForItemAtIndexPath
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let cell = collectionView.cellForItemAtIndexPath(indexPath) //returns nil
var width = cell?.bounds.width
return CGSizeMake(width!, 50)
}
有小费吗? 谢谢!
在sizeForItemAtIndexPath
返回文本的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return [(NSString*)[arrayOfStats objectAtIndex:indexPath.row] sizeWithAttributes:NULL];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.