Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. extension UICollectionView {
  2. func getCellSize(numberOFItemsRowAt: Int, cellRatio: CGFloat) -> CGSize {
  3. var screenWidth = UIScreen.main.bounds.width
  4. if #available(iOS 11.0, *) {
  5. let window = UIApplication.shared.keyWindow
  6. let leftPadding = window?.safeAreaInsets.left ?? 0
  7. let rightPadding = window?.safeAreaInsets.right ?? 0
  8. screenWidth -= (leftPadding + rightPadding)
  9. }
  10. let cellWidth = screenWidth / CGFloat(numberOFItemsRowAt)
  11. let cellHeight = cellWidth * cellRatio
  12. return CGSize(width: cellWidth, height: cellHeight)
  13. }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement