Upgrade to Pro — share decks privately, control downloads, hide ads and more …

なあ兄弟、 余白の意味を考えてから UI実装してくれ!

Avatar for Ryomm Ryomm
November 26, 2025

なあ兄弟、 余白の意味を考えてから UI実装してくれ!

2025.11.26 Mobile Fusion Study @KTC

Avatar for Ryomm

Ryomm

November 26, 2025
Tweet

More Decks by Ryomm

Other Decks in Programming

Transcript

  1. "Hey, seriously!? Do you even fucking understand the meaning of

    margins!?" Even Ryommcat was so surprised. All I can do is give a wry smile.*
  2. Here’s what I want to share today. *Margins are not

    just empty spaces—they are intentionally used blank areas!* To understand the meaning of margins, you first need some basic knowledge of cognitive psychology, so I’ll explain briefly.
  3. One of the core concepts in cognitive psychology is Gestalt

    psychology. Gestalt psychology is based on the fundamental idea that "when people perceive things, they tend to see them not as individual parts, but as a unified whole (a "Gestalt")."
  4. For example, if there is a picture of an apple,

    recognizing it as an "apple" rather than just a collection of dots and lines is what this refers to.
  5. And in Gestalt psychology, there is a principle called the

    "the law of Prägnanz" which describes a phenomenon in human perception grouping. Let me introduce the four main factors. First, there is the "Law of proximity". Objects that are close to each other tend to be perceived as a group.
  6. These brackets are evenly spaced, but the law of symmetry

    has a stronger effect than the law of proximity.
  7. Brackets that are closed together are perceived as a group,

    while those that are not closed are harder to perceive as a group.
  8. It's easy to perceive the items as alternating pairs of

    black-and-white and colored ones, but seeing them as alternating pairs of color and black-and-white, or black-and-white and color, feels a bit unnatural.
  9. Fourth, "Law of closure" Elements that form a smooth, continuous

    curve tend to be perceived as a group. For example, in this illustration, people are likely to recognize it as "two circles," rather than as "two incomplete circles and one rugby ball shape."
  10. The law of Prägnanz, which allows us to perceive these

    groupings, is also applied in UI design to organize information into chunks and make it easier to recognize.
  11. The factors related to proximity seem to be around here.

    You can see that items placed close to each other represent related information.
  12. Next, the factors that seem to be the factors related

    to symmetry . By enclosing the elements in a rectangle, the items inside appear to be grouped together as one.
  13. Next, these seem to be the factors related to similarity.

    Because they have the same shape, you can perceive them as a single group.
  14. Now that you all know about the law of prägnanz,

    you should be able to see groups like these in this screen. So, what do you think is important in UI design that makes information easy to recognize?
  15. *Margins are not just empty space; they are intentionally used

    blank areas.* You understand the meaning of the statement at the beginning now, right? When a wide margin is given, it indicates that the items belong to different groups, and when margins are evenly distributed, it means those elements are of equal importance or information.
  16. By the way, there are three ways to specify margins

    in SwiftUI: spacing in elements like VStack, padding, and Spacer. Let's consider how to use each of these based on the meaning of margins.
  17. For example, if these elements have a title-content relationship, the

    two pieces of information are related and should be grouped together.
  18. With that in mind, you can see that they should

    be treated as a single unit by enclosing them in a VStack.
  19. The same applies even if the number of elements increases.

    Title A and Content A form one group, and Title B and Content B form another group. If these two groups have the same level of information granularity, you should wrap them in a VStack and give them uniform spacing.
  20. Let’s consider what happens when there are even more content

    elements. Can you see that the size of the margins represents the grouping of each set of elements? - The margin between the title and the content is always 8pt, so if you see an 8pt margin, you can recognize that it’s between a title and its content. - The outer VStack consistently applies a 20pt margin, so if there’s a 20pt margin, you can recognize that it indicates a change of section. - Each content element is given a uniform 4pt margin. No matter how many content elements are added, if they are separated by 4pt, you can recognize that they belong to the content of Title B. In this way, you should use the spacing property of VStack or HStack to create whitespace that expresses the grouping of information, and group information appropriately.
  21. Now, let's look at another approach. The bottom margin on

    this screen is just empty space that doesn't have any meaning related to information recognition. For this kind of true empty space, it's a good idea to use Spacer().
  22. Finally, regarding padding: padding refers to the "space set inside

    an element." Since borders are also considered elements, the proximity between the border and the text can make it harder to read. To prevent this, adding space inside the element (padding) makes it easier to recognize and read.
  23. By the way, in the first example, the highlighted area

    is treated as the range of element A. Before you implement it, please consider whether this way of adding padding is actually appropriate and whether it aligns with the design intent.
  24. Now, up to this point, can you see that implementing

    with SwiftUI involves laying out groups and hierarchies of information? You can think of a SwiftUI file as a document that represents a collection of related information.
  25. However, some people might think, “Wrapping everything in a VStack

    and nesting the code so deeply makes it hard to read!
  26. It's an engineer's responsibility to understand the intent behind UI

    design and translate it into implementation.
  27. See? Bro, from now on, make sure you understand the

    purpose of margins before implementing the UI.