কম্পিউটার টিউটোরিয়াল

সুইফটে UICollectionView ব্যবহার করার পদ্ধতি


UICollectionView ব্যবহার করতে DataSource, Delegate এবং অপশনালি DelegateFlowLayout কনফর্ম করুন।

প্রোগ্রাম্যাটিক্যালি কালেকশন ভিউ তৈরি —

func initCollection() {
    let layout = UICollectionViewFlowLayout()
    layout.itemSize = CGSize(width: 50, height: 50)
    let collection = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
    collection.dataSource = self
    collection.delegate = self
    collection.backgroundColor = .systemGreen
    collection.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
    self.view.addSubview(collection)
}

DataSource মেথড —

func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 }
func collectionView(_ collection: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 7 }
func collectionView(_ collection: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collection.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
    cell.layer.backgroundColor = UIColor.systemRed.cgColor
    return cell
}

অপশনাল: ডাইনামিক সেল সাইজ (DelegateFlowLayout) —

func collectionView(_ collection: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: 200, height: 50)
}

ফলাফল —

সুইফটে UICollectionView ব্যবহার করার পদ্ধতি


  1. সুইফটে MBProgressHUD ব্যবহার করার পদ্ধতি

  2. Swift-এ স্ট্যাটিক ভেরিয়েবল (Static Variable) কোথায় এবং কীভাবে ব্যবহার করবেন

  3. মাইক্রোসফট এজ-এ কালেকশন (Collections) ব্যবহার করার পদ্ধতি

  4. এজ ইনসাইডার কালেকশনস মास্টার করুন: ধাপে ধাপে গাইড