margin

2025. 8. 3. 20:22·iOS/UIKit
반응형

👋 들어가기 전

오늘은 margin 관련된 내용을 조금 정리해보려고 한다.


🏁 학습할 내용

  • margin
    • 특징
    • layoutMargins vs directionalLayoutMargins
    • insetsLayoutMarginsFromSafeArea
    • isLayoutMarginsRelativeArrangement

🧩 Margin

 

📌 개념

현재 뷰와 컨텐츠 사이의 간격을 의미한다.

 

✅ 특징

  • 양수 값은 뷰의 중심쪽, 음수 값은 바깥쪽을 가리킨다.
  • 뷰 바깥 쪽이 아닌, 안쪽으로 커진다.

 

🥊 layoutMargins vs directionalLayoutMargins

마진을 주는 방법은 2가지가 있는데, 차이를 알아보자.

항목 layoutMargins directionalLayoutMargins
타입 UIEdgeInsets NSDirectionalEdgeInsets
방향성 왼쪽/오른쪽 기준 (left, right) 시작/끝 기준 (leading, trailing)

 

가장 큰 특징은 directionalLayoutMargins은 LTR, RTL을 고려한다.

또한 iOS11 이후부터는 directionalLayoutMargins 사용을 권장한다.

 

🦺 insetsLayoutMarginsFromSafeArea

safeArea의 여백을 layoutMargin에 포함할지 말지를 결정한다.

 

  • true일 때: safe area의 inset 값이 layoutMargins에 포함됨
  • false일 때: safe area의 inset 값이 layoutMargins에 포함되지 않음

 

🚩 isLayoutMarginsRelativeArrangement

 

UIStackView에 margin을 적용하지, 말지를 나타내는 플래그 프로퍼티다.

 

margin을 적용하더라도, 이 프로퍼티를 true로 바꾸지 않으면 적용이 무시된다.


출처

https://developer.apple.com/documentation/uikit/uiview/insetslayoutmarginsfromsafearea

 

insetsLayoutMarginsFromSafeArea | Apple Developer Documentation

A Boolean value indicating whether the view’s layout margins are updated automatically to reflect the safe area.

developer.apple.com

https://ios-development.tistory.com/1498

 

[iOS - swift] UIStackView에 padding 넣는 방법 (UIStackView Margin, isLayoutMarginsRelativeArrangement, directionalLayoutMar

UIStackView의 padding 보통 UIStackView를 사용하면 UIStackView안의 아이템들 spacing은 setCustomSpacing(_:after:) 메소드를 사용하여 구현이 가능 stackView.setCustomSpacing(16, after: label1) 만약 UIStackView에 추가한 아이

ios-development.tistory.com

https://developer.apple.com/documentation/uikit/uilistcontentconfiguration/3600530-directionallayoutmargins

 

directionalLayoutMargins | Apple Developer Documentation

The margins between the content and the edges of the content view.

developer.apple.com

https://developer.apple.com/documentation/uikit/uistackview/islayoutmarginsrelativearrangement

 

isLayoutMarginsRelativeArrangement | Apple Developer Documentation

A Boolean value that determines whether the stack view lays out its arranged views relative to its layout margins.

developer.apple.com

 

반응형

'iOS > UIKit' 카테고리의 다른 글

preferredMaxLayoutWidth  (0) 2025.08.26
CALayer란  (1) 2025.08.24
NSTextAttachment  (2) 2025.07.23
[Text 시리즈 3] TextKit1  (5) 2025.07.21
[Text 시리즈 2] Font Metrics 와 Glyph metrics  (5) 2025.07.18
'iOS/UIKit' 카테고리의 다른 글
  • preferredMaxLayoutWidth
  • CALayer란
  • NSTextAttachment
  • [Text 시리즈 3] TextKit1
Hamp
Hamp
남들에게 보여주기 부끄러운 잡다한 글을 적어 나가는 자칭 기술 블로그입니다.
  • Hamp
    Hamp의 분리수거함
    Hamp
  • 전체
    오늘
    어제
    • 분류 전체보기 (325) N
      • CS (30)
        • 객체지향 (2)
        • Network (7)
        • OS (6)
        • 자료구조 (1)
        • LiveStreaming (3)
        • 이미지 (1)
        • 잡다한 질문 정리 (0)
        • Hardware (2)
        • 이론 (6)
        • 컴퓨터 그래픽스 (0)
      • Firebase (3)
      • Programing Langauge (41)
        • swift (34)
        • python (6)
        • Kotlin (1)
      • iOS (133) N
        • UIKit (37)
        • Combine (1)
        • SwiftUI (33) N
        • Framework (7)
        • Swift Concurrency (22)
        • Tuist (6)
        • Setting (11)
        • Modularization (1)
        • Instruments (6)
      • PS (59)
        • 프로그래머스 (24)
        • 백준 (13)
        • LeetCode (19)
        • 알고리즘 (3)
      • Git (18)
        • 명령어 (4)
        • 이론 (2)
        • hooks (1)
        • config (2)
        • action (7)
      • Shell Script (2)
      • Linux (6)
        • 명령어 (5)
      • Spring (20)
        • 어노테이션 (6)
        • 튜토리얼 (13)
      • CI-CD (4)
      • Android (0)
        • Jetpack Compose (0)
      • AI (9)
        • 이론 (9)
        • MCP (0)
  • 블로그 메뉴

    • 홈
    • 태그
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    투포인터
    boostcamp
    SwiftUI
    AVFoundation
    CS
    백준
    lifecycle
    dp
    dispatch
    concurrency
    IOS
    Tuist
    property
    protocol
    Swift
    UIKit
    GIT
    프로그래머스
    dfs
    Spring
  • 최근 댓글

  • 최근 글

  • 반응형
  • hELLO· Designed By정상우.v4.10.0
Hamp
margin
상단으로

티스토리툴바