-5

How do i add spacing between each cell here -

    for i in 0...50 {
        let cell = UIView()
        cell.backgroundColor = .lightGray
        cell.frame = CGRect(x: Double(i) * Double(32.52), y: 90, width: 350, height: 500)
        view.addSubview(cell)
    }

Because with the code above the view looks like this

Screenshot

T-Heron
  • 5,385
  • 7
  • 26
  • 52
bernan
  • 15
  • 2
  • 1
    What exactly are you trying to do? It looks like your code is just laying a bunch of views on top of each other. Maybe you should set your view width to 32.52 and the x position to `Double(i) * Double(32.52) + i*3` to give a 3 point space between your cells. – toddg Apr 15 '17 at 15:14

1 Answers1

0

Your cells are much too wide for the increment you're using horizontally. Your increment offsets them by 32.52 (why the fractional part?) and the views have a width of 350.

So your view spans will be:

From X  up to 
------  -----
0       350
32.52   403.52  (overlapping from 32.53 to 350)
65.04   456.04  (overlapping from 65.04 to 403.52)
and so on ...

You probably meant to use a narrower frame width (or a larger increment).

The spacing will be the difference between your increment and the frame width.

For example: an increment of 32 with a width of 30 will give you a 2 pixel gap between views.

Alain T.
  • 40,517
  • 4
  • 31
  • 51
  • I was trying to have the app look like tinder, i wanted the cell to have the image of a user with name and the age inside of it. I was trying to do that but i'm still new to swift. Anyways, thanks for your help. – bernan Apr 16 '17 at 11:35
  • You should look into UITableView for this. – Alain T. Apr 16 '17 at 14:13