我有一個包含圖像視圖和標籤的UICollectionViewCell。動態設置UICollectionViewCell的大小
只有當我有圖像視圖時,才能動態調整單元格大小。
我在自動佈局的imageView下添加了一個標籤。
On viewDidLoad圖像被截斷或文本被截斷。如何動態調整UICollectionViewCell中的圖像視圖和標籤的大小。
以下是我的代碼,只有與ImageView的
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
let imageSize = model.images[indexPath.row].size
return imageSize
}
我有文字和圖片從我在哪裏顯示內容的數組工作。
任何幫助將不勝感激。謝謝。
它可以幫助你https://possiblemobile.com/2016/02/sizing-uicollectionviewcell-fit-multiline-uilabel/ –