Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension UICollectionView {
- func getCellSize(numberOFItemsRowAt: Int, cellRatio: CGFloat) -> CGSize {
- var screenWidth = UIScreen.main.bounds.width
- if #available(iOS 11.0, *) {
- let window = UIApplication.shared.keyWindow
- let leftPadding = window?.safeAreaInsets.left ?? 0
- let rightPadding = window?.safeAreaInsets.right ?? 0
- screenWidth -= (leftPadding + rightPadding)
- }
- let cellWidth = screenWidth / CGFloat(numberOFItemsRowAt)
- let cellHeight = cellWidth * cellRatio
- return CGSize(width: cellWidth, height: cellHeight)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement