সুইফট 4 সুইফট 4 আইওএস সংগ্রহ ভিউ সংগ্রহের ভিউ উদাহরণ এক্সকোড সর্বশেষ কোড ওয়ার্কিং নমুনা
এটি শীর্ষের প্রতিনিধি বিভাগে যুক্ত করুন
ইউআইকোলিকেশনভিউডেলিগেটফ্লোএলআউট
এবং এই ফাংশন ব্যবহার করুন
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = (self.view.frame.size.width - 20) / 3
let height = width * 1.5
return CGSize(width: width, height: height)
}
///// নমুনা সম্পূর্ণ কোড
সংগ্রহ ভিউ এবং স্টোরিবোর্ডে কালেকশন ভিউ সেল তৈরি করুন সংগ্রহে উল্লেখ করুন
@ আইবিআউটলেট দুর্বল ভার সিভিসিন্ট হিসাবে: ইউআইকোলিকেশনভিউ!
এটি দেখুন নিয়ামকটিতে পেস্ট করুন
import UIKit
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
var arrVeg = [String]()
var arrFruits = [String]()
var arrCurrent = [String]()
@IBOutlet weak var cvContent: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
arrVeg = ["Carrot","Potato", "Tomato","Carrot","Potato", "Tomato","Carrot","Potato", "Tomato","Carrot","Potato", "Tomato"]
arrVeg = ["Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange","Mango","Papaya","Orange"]
arrCurrent = arrVeg
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let width = (self.view.frame.size.width - 20) / 3
let height = width * 1.5
return CGSize(width: width, height: height)
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return arrCurrent.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! ContentCollectionViewCell
cell.backgroundColor = UIColor.green
return cell
}
}