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.
Asked
Active
Viewed 78 times
-1
-
1Please check tag for question , its regarding ios. – PRATEEK BHARDWAJ Feb 22 '18 at 11:48
-
Ok, now what did you try already? share your code and describe what does not work as you expect.. – Milan Nosáľ Feb 22 '18 at 11:51
-
https://github.com/maximbilan/UICollectionViewHorizontalPaging this one i have tried , but it does not work after merging in my source code. – PRATEEK BHARDWAJ Feb 22 '18 at 11:52
-
you can try below solution as suggested by Arek Holko https://stackoverflow.com/a/19435898/6356502 – Manish Malviya Feb 22 '18 at 12:03
-
@PrateekBhardwaj Please post your code so that we can look into the not working stuff – Sahil Manchanda Feb 23 '18 at 05:29
1 Answers
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,364
- 2
- 21
- 35