【发布时间】:2015-01-27 12:24:35
【问题描述】:
当我尝试为集合视图的单元格赋予动态时,根据它将包含的标签,单元格之间的间距发生了一些奇怪的事情:
如果我将项目设置为静态宽度,则单元格将按预期布局:
给项目一个宽度的代码是:
func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: UICollectionViewLayout!,
sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize
{
let element = self.default_categories[indexPath.row] as NSString
let stringSize = element.sizeWithAttributes([NSFontAttributeName: UIFont.systemFontOfSize(18.0)])
// return CGSize(width: stringSize.width, height: self.categoriesView.frame.height)
return CGSize(width: 100, height: self.categoriesView.frame.height)
}
所以,基本上,我真的不知道那个空间是从哪里来的,当我 尝试为单元格提供动态宽度。
sectionInset 为 (0, 0, 0, 0),minimumLineSpacing 也是 0。
【问题讨论】:
-
与论坛网站不同,我们不使用“谢谢”、“感谢任何帮助”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?。顺便说一句,这是“提前致谢”,而不是“致谢”。
-
fk2blow:@JohnSaunders 在这里是正确的。请阅读他发布的链接。你争论的 cmets 也没有“帮助社区”,但你发布了它们。
标签: ios autolayout uicollectionview uicollectionviewcell