How can I add multiple collection views in a UIViewController in Swift?

前端 未结 5 1399
栀梦
栀梦 2020-12-07 08:35

I tried many days to realise this: \"enter

I want to add in my UIViewController two di

5条回答
  •  轮回少年
    2020-12-07 09:09

    You can also name the collection views outlets differently (without subclassing):

    @IBOutlet weak var collectionView: UICollectionView!
    
    @IBOutlet weak var SecondCollectioView: UICollectionView!
    

    method:

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "customCell", for: indexPath) as UICollectionViewCell
    
        if(collectionView == self.SecondCollectioView) {
            cell.backgroundColor = UIColor.black
        } else {
             cell.backgroundColor = self.randomColor()
        }
    
        return cell;
    }
    

    This is will be an another way.

提交回复
热议问题