containerRelativeFrame

2025. 10. 23. 13:27·iOS/SwiftUI
반응형

containerRelativeFrame

 

🧩  역할

현재 뷰의 프레임을, 컨테이터를 기준으로, 일정한 칸(count)의로 나누고, 그 중
몇 칸(span)을 차지할 지 명시하여, 프레임을 설정한다.

 

 

📘 기본 문법

.containerRelativeFrame(
    _ axis: Axis, // 계산축
    count: Int, // 컨테이너 기준 몇 칸으로 나눌 지
    span: Int, // 차지할 칸 개수
    spacing: CGFloat = 0 // 칸 사이 간격
)

 

 

📏 예시

ScrollView(.horizontal) {
    LazyHStack(spacing: 10.0) {
        ForEach(viewModel.sections) { item in
            Rectangle()
                .fill(.purple)
                .aspectRatio(3.0 / 2.0, contentMode: .fit)
                .containerRelativeFrame(
                    .horizontal, count: 4, span: 1, spacing: .zero)
        }
    }
}

출처

https://developer.apple.com/documentation/SwiftUI/View/containerRelativeFrame(_:alignment:)

 

containerRelativeFrame(_:alignment:) | Apple Developer Documentation

Positions this view within an invisible frame with a size relative to the nearest container.

developer.apple.com

 

반응형

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

PreferenceKey  (0) 2025.10.24
.id  (0) 2025.10.23
SwiftUI 동작 방식  (0) 2025.10.18
textContentType  (0) 2025.10.03
Navigator 패턴 이용해보기  (0) 2025.09.28
'iOS/SwiftUI' 카테고리의 다른 글
  • PreferenceKey
  • .id
  • SwiftUI 동작 방식
  • textContentType
Hamp
Hamp
남들에게 보여주기 부끄러운 잡다한 글을 적어 나가는 자칭 기술 블로그입니다.
  • Hamp
    Hamp의 분리수거함
    Hamp
  • 전체
    오늘
    어제
    • 분류 전체보기 (304)
      • CS (30)
        • 객체지향 (2)
        • Network (7)
        • OS (6)
        • 자료구조 (1)
        • LiveStreaming (3)
        • 이미지 (1)
        • 잡다한 질문 정리 (0)
        • Hardware (2)
        • 이론 (6)
        • 컴퓨터 그래픽스 (0)
      • Firebase (3)
      • Programing Langauge (37)
        • swift (32)
        • python (4)
        • Kotlin (1)
      • iOS (132)
        • UIKit (37)
        • Combine (1)
        • SwiftUI (32)
        • 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 (13)
        • 어노테이션 (1)
        • 튜토리얼 (11)
      • CI-CD (4)
      • Android (0)
        • Jetpack Compose (0)
  • 블로그 메뉴

    • 홈
    • 태그
  • 링크

  • 공지사항

  • 인기 글

  • 태그

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

  • 최근 글

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

티스토리툴바