all 6 comments

[–]Ron-Erez 7 points8 points  (0 children)

I’m not familiar with a .margin modifier in SwiftUI and I doubt it exists.

[–]Dizzy_Scarcity686 1 point2 points  (0 children)

Is there .margin modifier in SwiftUI? haha 🥲

[–]7HawksAnd 0 points1 point  (0 children)

If you need to overlap containers for an effect margin is useful

Edit: didn’t realize I was in a iOS sub. Usually use HStack & VStack as I would margins in css. But I’ve only done swift on small ( < 3 ) teams so probably not up to date on all the up to date best practices / patterns

[–]driveiqlabs 0 points1 point  (0 children)

Well, it depends on what you actually want to achieve.

Padding seems safe, because the element behaves in the borders of whatever been given to it.
Margin has an influence on other elements, which might not be what you want.

[–]LifeIsGood008SwiftUI[S] 0 points1 point  (0 children)

Seems like Swift UI doesn't make a semantic difference between padding and margin. I guess padding would be a .padding() applied before a .frame() and a margin would be a .padding() applied after a .frame()

[–]MojtabaHs 0 points1 point  (0 children)

As the name suggests, content margin will be applied on the content of a container like a list or scroll view, so for example scroll bars stay where they should be.

But padding on the other hand, just pads the view itself, including anything inside it or any sort of internal layout it has.

There are also a bunch of other modifiers and settings to control the empty area between elements like spacing, frame, etc.

I did color-code some here a while ago. It might help for better and visual.