I want to make two rows collection view in horizontal like below
I am new in iOS development, and some tutorials just give example how to make certain number of columns of collection view vertically, but i need to limit the number of rows of the collection view
I have tried to make the number of section to be two but still, the number of row still one
import UIKit
class ViewController: UIViewController, UICollectionViewDataSource{
@IBOutlet var collectionView: UICollectionView!
let imageArray = [UIImage(named: "image1"),UIImage(named: "image2"),UIImage(named: "image3"),UIImage(named: "image4"),UIImage(named: "image5"),UIImage(named: "image6"),UIImage(named: "image8"),UIImage(named: "image9")]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "imageCell", for: indexPath) as! ImageCell
cell.avatarView.image = imageArray[indexPath.item]
return cell
}
}

