我有来自服务器的单词,并且动态地设置了集合视图,每个单元显示一个字母。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
文字是否缩小可以吗? –