How to center align the cells of a UICollectionView in Swift3.0?
<h2>Description:</h2>

<p>Answer for <code>Objective-C</code> and <code>Swift2.0</code>: <a href="https://stackoverflow.com/questions/13588283/how-to-center-align-the-cells-of-a-uicollectionview">How to center align the cells of a UICollectionView?</a> </p>

<p>I usually would try to convert the <code>Swift2.0</code> answer to the <code>Swift3.0</code> solution, however the method:</p>

<pre><code>func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -&gt; UIEdgeInsets {
        let edgeInsets = (screenWight - (CGFloat(elements.count) * 50) - (CGFloat(elements.count) * 10)) / 2
        return UIEdgeInsetsMake(0, edgeInsets, 0, 0);
    }
</code></pre>

<p>doesn't seem to exist in <code>Swift3.0</code>,and the only other method I found that seems useful is:</p>

<pre><code>func collectionView(_ collectionView: UICollectionView, transitionLayoutForOldLayout fromLayout: UICollectionViewLayout, newLayout toLayout: UICollectionViewLayout) -&gt; UICollectionViewTransitionLayout {
        &lt;#code#&gt;
}
</code></pre>

<p>but I am unsure how to implement it correctly.</p>

<h2>Question:</h2>

<p>How to center align the cells of a <code>UICollectionView</code> in <code>Swift3.0</code>?</p>

<p>(A simple and general solution for iOS and tvOS would be perfect)</p>