How do I properly design my own custom table cell?

36 Views Asked by At

I designed a special table cell, but when the application runs, its display is broken. How can I set this. (I'm new to iOS development)

Thank you :)

My cell design enter image description here

Simulator İmage enter image description here

1

There are 1 best solutions below

0
multiverse On BEST ANSWER

In your code like say below

class DemoTableViewCell: UITableViewCell {

You will have a method like

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

        return CGSize(width:((collectionView.frame.size.width)/1.6 - 28), height:300)



    }

here you can decide the width ,height of cell

also do not forget to set the number of rows you want inside another method

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
       return 3 <—— depends on the array count you are fetching data from
        
    }

You see the compiler is intelligent and so if the framework , but we still need to provide it information, to display the data correctly.