T
T
Tommy322017-02-03 03:30:41
Apple Xcode
Tommy32, 2017-02-03 03:30:41

How to properly adapt UICollectionView?

Where can I find information to adapt cell in collectionview. The task is simple, but it turned out to be difficult for me to fool, to make the same indents from the edges for the cell for all screen extensions. So that it looks like a table of elements and on all screens it looks like a table of elements, and not like it is now, if you look at it on a tablet, it's generally terrible.b586b3e197f24441910596100c5edf87.png28c8964683584630b72c9b2962876713.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Beltyukov, 2017-02-05
@Tommy32

There are several nuances here.
For a collection, indentation is a secondary value. First of all, you control the size of the cell. To do this, you need your ViewController to implement the protocol UICollectionViewDelegateFlowLayout and be set as a delegatecollection. Then you can set the size of the cell that will fill the screen in width:

extension /*Ваш класс*/ : UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: UIScreen.main.bounds.size.width - 2*/*размер вашего отступа*/, height: /*желаемая высота*/)
    }
}

PS For a beginner to build a simple table, it may be more convenient to use UITableView

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question