-1

How do I set a horizontal orientation to a collection view in Swift? I need want the row layout to be like the picture below.

Reference Screen is as follows :-

kbunarjo
  • 1,008
  • 1
  • 8
  • 24
PRATEEK BHARDWAJ
  • 2,100
  • 2
  • 21
  • 34

1 Answers1

0
@IBOutlet weak var collectionView: UICollectionView!
let cellIdentifier = "cellViewID"
let objects = ["Cat", "Dog", "Fish"]

let images_array = ["break_down_grey", "break_down_grey", "Fish"]

func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return objects.count;
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {


let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! CustomCollectionViewCell

cell.title.text=objects[indexPath.row]
cell.imageView.image = UIImage(named: images_array[indexPath.row])
print(cell)
return cell
}



func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        print("Cell \(indexPath.row) selected")
}

import UIKit

class CustomCollectionViewCell: UICollectionViewCell {



        @IBOutlet  weak var imageView: UIImageView!
        @IBOutlet weak var title: UILabel!



    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

}
PRATEEK BHARDWAJ
  • 2,100
  • 2
  • 21
  • 34