NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

Day 23 – Milestone: Projects 1-3 CHALLENGE

Forums > 100 Days of Swift



I have finished all the requirments for this chanllenge, however, I'm struggling with how to add spacing between uitableview cells.

All my cell rows are bunched up together with no breathing room between the associated images and texts.



I strongly believe that in order to set the cell insets for the image, you would have to create a custom cell class. So, what I recommend to do now is to separate the flag images by adding borders to them. In cellForRowAt method put these 2 lines in:

cell.imageView?.layer.borderWidth = 1
cell.imageView?.layer.borderColor = UIColor.lightGray.cgColor

Now it should look better.

Once you reach the days where you learn about custom classes, you can go back to this project and improve it, using the technique from this video:



@MateusZ that was really helpful, but i was wondering about how to set border as well in the detail view controller to sarround the flags. i tried to set the broder to the image view itself but it was always far away and not sarrounding the flag itself.


Simply say using insets, but it is kind of tricky for default cell, prefer to use custom cell to do it.

See this thread

@sugertag Try to set imageView's aspect ratio to 2:1 in storyboard.

Or set its constraint programmtically. imageView.heightAnchor.constraint(equalTo: imageView.widthAnchor, multiplier: 1.0/2.0).isActive = true


Thanks @mateuz!

I'm working on <a href=''></a> and I was facing same problem. Thanks for sharing your experience regarding this issue.



Hacking with Swift is sponsored by Fernando Olivares

SPONSORED Would you describe yourself as knowledgeable, but struggling when you have to come up with your own code? Fernando Olivares has a new book containing iOS rules you can immediately apply to your coding habits to see dramatic improvements, while also teaching applied programming fundamentals seen in refactored code from published apps.

Try the book!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.