0

My goal is to have full text in a middle cell and truncated text in other cells, but with change of middle cell this style should not change (means middle one full text and others truncated).

Presets: Infinite scroll in horizontally scrolling collection view with label in the cells.

I have 3 cells and they should look like this [ 1D ]---[ 1 Day ]---[ 1D ]

Dake
  • 23
  • 8
  • if its anyway infinite horizontal scroll collectionView why would you have truncated text in side cells? Rather you can have truncated cells (cells appearing partially on sides) while center cell shown completely. All cells will have complete text, side cells will only be shown partially so is the text. If thats all u need enable paging in CollectionView that should do the job – Sandeep Bhandari Jun 13 '18 at 08:23
  • I have 3 cells and they should look like this [ 1D ]---[ 1 Day ]---[ 1D ] – Dake Jun 13 '18 at 08:25
  • Effect will be same even if u show cell with 1 Day full while other two cells shown partially is what am saying, u need not truncate text but make your collectionView layout such that only center cell is shown full while other two cells shown partially – Sandeep Bhandari Jun 13 '18 at 08:26
  • I am not getting what do you, could explain more clearly – Dake Jun 13 '18 at 08:28

1 Answers1

0

You can do something like this to find the middle cell:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "CELL_ID", for: indexPath)

    let center = self.view.convert(collectionView.center, to: collectionView)
    let index = collectionView.indexPathForItem(at: center)

    if (indexPath == index) {
        // truncated text
    } else {
        // don't truncated text
    }

    return cell
}
Asaf Shveki
  • 736
  • 8
  • 11