我有來自服務器的單詞,並且動態地設置了集合視圖,每個單元顯示一個字母。UICollectionview動態適合一行
但如果這個詞太長,那麼一切都縮水。
我想每個字母以適應集合視圖,這個詞應該適合在一行而已,所以我用:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let numberOfSets = CGFloat(self.letters!.count)
let width = (collectionView.frame.size.width - (numberOfSets * view.frame.size.width/15))/numberOfSets
let height = collectionView.frame.size.height/2
return CGSize(width : width, height : height)
}
你必須如果您不希望它們縮小,請保持collectionViewCell的寬度不變。 –
@SanketBhavsar我希望他們縮小,但比例..如何可以保持不變?他們不會合併成一行 – knic1ned
文字是否縮小可以嗎? –