joda
joda

Reputation: 731

set margin to collection view's cell

I'm beginner with collection view, I need to create cell like this

enter image description here

Can I do it from Storyboard? I want to add margin of cell = 4 or 5 in the top, bottom, lift and right in iPhones and iPads of all sizes, or I if need to do that programmatically How I can add the contents of the cell like the image above?

Upvotes: 1

Views: 584

Answers (1)

matt
matt

Reputation: 535576

There is no "margin" here. There is simply a rectangle with a shadow, and everything else is drawn in front of it. The simplest solution is probably a custom UIView that draws itself as a rectangle with a shadow. Make that the content view's direct subview, and everything else in the cell is a subview of that. The inset of the rectangle-with-shadow within the cell's content view can be determined by autolayout (and the position of all the stuff inside it can be determined by autolayout too).

Thus it was trivial for me to obtain this sort of thing:

enter image description here

And of course you can tweak the border color, the background color, and so forth.

Upvotes: 1

Related Questions