how to create custom UICollectionViewCell

前端 未结 3 1694
一向
一向 2021-01-16 11:37

I have a UICollectionView and Im trying to set a label and an image in the collectionViewCell. Unfortunately I cant seem

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-16 12:17

    1. Create subclass of UICollectionViewCell. For instance TestCollectionViewCell.
    2. In Storyboard drag label in cell and set "Custom class" for this UICollectionViewCell with your created class. Set Reusable identifier, if your collection view in UIViewController don't forget to set DataSource and Delegate for that collectionView.
    3. Connect IBOutlet in your Cell subclass.
    4. Set at least 1 value inside numberOfItemsInSection method.
    5. Then use your subclass of cell in cellForItemAt and try set text for a label.

提交回复
热议问题