1

For expanding label in UICollectionViewCell, I am using this library

My code is as below:

label.delegate = self
label.shouldCollapse = true
label.numberOfLines = 4
label.collapsed = true

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

let size: CGSize = "Modern Furniture reflects the design ilosophy of form following function prevalent in modernism. These designs represent the ideals of cutting excess, practicality and an absence of decoration.".size(withAttributes: [NSAttributedString.Key.font: UIFont.font_light(14)])
            return CGSize(width: collectionView.frame.size.width , height: size.height + 390)

}

This thing works for UITableViewCell but it isn't working for UICollectionViewCell. In fact, the labels delegate methods are also not called.

  • 1
    I recommend you not to use library for this situation. just reload the collectionViewCell with new height and UILabel. less libraries = more stable code – user1105951 Aug 08 '19 at 10:10
  • @user1105951Can you please share the code? – Vena Champaneri Aug 08 '19 at 11:01
  • google it. "self sizing cell" or you calculate the height of the string your self (recommended) . check start here : https://stackoverflow.com/questions/30450434/figure-out-size-of-uilabel-based-on-string-in-swift – user1105951 Aug 08 '19 at 16:20

0 Answers0