[英]Spacing is not correct in CollectionView when cell having dynamic width?
[英]collectionview cell dynamic width breaks layout
當我嘗試給集合視圖的單元格添加動態信息時,根據其將包含的標簽,單元格之間的間距發生了奇怪的變化:
如果我將給出靜態寬度的項目隔開,則按預期方式對單元進行布局:
使項目具有寬度的代碼是:
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。
問題在於布局的“ minimumInteritemSpacing”屬性。 當添加動態大小時,將其設置為0會刪除單元格之間的邊距。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.