How to show a message when collection view is empty

前端 未结 5 1275
無奈伤痛
無奈伤痛 2021-02-07 05:54

I`m trying to show a message only when my collection view is empty. Well, I try set return 1 when my if is true but when I have this, it only show one item in my collection view

5条回答
  •  遇见更好的自我
    2021-02-07 06:41

    Why don't you use:

    open var backgroundView: UIView?

    // will be automatically resized to track the size of the collection view and placed behind all cells and supplementary views.`

    You can show it whenever collection is empty. Example:

    var collectionView: UICollectionView!
    var collectionData: [Any] {
        didSet {
            collectionView.backgroundView?.alpha = collectionData.count > 0 ? 1.0 : 0.0
        }
    }
    

提交回复
热议问题