Spacing between collection view cells will be uneven without performing some simple math to calculate the correct size of the cells when including space. In this video, see what code must be added to create perfectly evenly spaced collection view cells.
- [Instructor] Our next step…is to define the spacing between items.…Now we have four items per row,…and what we want to do is put space between each of them.…But not on the edges.…So there'll be space here,…here,…and here.…So the amount of spaces we have per each row,…is three.…We're going to have five points of space between each.…We can calculate the total space,…for each row,…by multiplying that by the number of spaces that we have.…
So we take the total number of items in the row,…subtract one, that gives us the number of spaces.…And then we can multiply that…by the space we want between each item.…To give us the total space that we want.…So with those thoughts in mind,…let's create the padding…for our app.…After defining items per row,…I'm going to define a value called padding.…That's going to be a CGFloat,…and we'll set that equal to five.…
Now what we need to do with the padding,…is use that in our size considerations.…So the next line,…will now have a total padding value.…And that's also going to be a CGFloat.…
- Advanced UI controls
- Creating alert controllers
- Displaying web content
- Creating a collection view controller
- Creating a custom data type
- Creating tabbed apps
- Importing and setting icons for your apps
- Publishing your app to the App Store
Skill Level Beginner
iOS and watchOS App Development: Notificationswith Steven Lipton3h 45m Intermediate
1. Mastering Views
2. Display Web Content
3. Collection Views
4. Multi-View Templates
5. Publish an App
Next steps1m 21s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.