Advertisement
Don_Mag

Untitled

Aug 28th, 2021
1,518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.73 KB | None | 0 0
  1. class ThemesVC: UIViewController {
  2.    
  3.     var images: [UIImage] = []
  4.    
  5.     override func viewDidLoad() {
  6.         super.viewDidLoad()
  7.        
  8.         images = ThemeManager().themeBackgroundImages()
  9.        
  10.         // whatever else you're doing in viewDidLoad
  11.         // ...
  12.     }
  13.    
  14. }
  15.  
  16. extension ThemesVC: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout{
  17.    
  18.     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  19.         return images.count
  20.     }
  21.    
  22.     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  23.         let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ThemesCollectionViewCell", for: indexPath) as! ThemesCollectionViewCell
  24.        
  25.         cell.contentView.layer.cornerRadius = 20
  26.        
  27.         cell.themeCellImageView.image = images[indexPath.row]
  28.        
  29.         return cell
  30.     }
  31.    
  32.     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
  33.         return UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
  34.     }
  35.    
  36.     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  37.         return 20
  38.     }
  39.    
  40.     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
  41.         return 20
  42.     }
  43.    
  44.     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  45.         return CGSize(width: view.frame.size.width/2.34, height: view.frame.size.height * 0.3)
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement