I dynamische Zellgröße in Textview per Text wollen, ist Hier mein CodeDynamische Höhe für UICollectionViewCell
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return DataArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? CustomCollectionViewCell
let fixedWidth = cell?.TextView.frame.size.width
cell?.TextView.sizeThatFits(CGSize(width: fixedWidth!, height: CGFloat.greatestFiniteMagnitude))
let newSize = cell?.TextView.sizeThatFits(CGSize(width: fixedWidth!, height: CGFloat.greatestFiniteMagnitude))
var newFrame = cell?.TextView.frame
newFrame?.size = CGSize(width: max((newSize?.width)!, fixedWidth!), height: (newSize?.height)!)
cell?.TextView.frame = newFrame!
TextViewFrame = newFrame!
cell?.TextView.text = DataArray[indexPath.row] as? String
return cell!
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
{
return CGSize(width: CV.frame.size.width, height: 200)
}
Hier i für Zelle 200 feste Größe gegeben haben. es gibt mir Ausgabe als unten Es gibt mir Zelle Höhe 200 für kleinen Inhalt sowie für großen Inhalt. Aber eigentlich möchte ich Zelle Höhe nach Inhalt. Wie kann ich das erreichen? Jede Hilfe wird geschätzt. Vielen Dank im Voraus
Gibt es eine maximale Grenze für die Länge der Zeichenfolge, die Sie in der Bezeichnung anzeigen werden? – Adeel
Nein, ich habe keine maximale Grenze angewendet –
Und was ist mit der minimalen Höhe einer Zelle? Besteht die Möglichkeit, dass die Zeichenfolge für eine Zelle leer ist? – Adeel