Files
2nd/10_Wiki/Topic_Programming/Coding/iOS_UIKit_AutoLayout_Patterns.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

3.8 KiB

id, title, category, status, source_trust_level, verification_status, created_at, updated_at, tags, tech_stack, applied_in, aliases
id title category status source_trust_level verification_status created_at updated_at tags tech_stack applied_in aliases
ios-uikit-autolayout-patterns UIKit AutoLayout 실전 패턴 Coding draft B conceptual 2026-05-09 2026-05-09
ios
uikit
autolayout
layout
vibe-coding
language applicable_to
Swift / UIKit
iOS
NSLayoutAnchor
priority
content hugging
compression resistance

UIKit AutoLayout 실전 패턴

AutoLayout 의 어려움은 (1) anchor / constraint API 자체가 아니라 (2) priority + hugging + compression resistance 의 의미와 (3) runtime 충돌 디버깅.

📖 핵심 개념

  • Constraint 는 식: view1.attribute = m * view2.attribute + c
  • Priority 1~1000: 1000 = required, 그 외 = optional. 충돌 시 priority 높은 게 이김.
  • Content hugging: "내가 늘어나기 싫어" 강도.
  • Compression resistance: "내가 줄어들기 싫어" 강도.

💻 코드 패턴

NSLayoutAnchor (UIKit native)

view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    view.topAnchor.constraint(equalTo: superview.safeAreaLayoutGuide.topAnchor, constant: 16),
    view.leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: 16),
    view.trailingAnchor.constraint(equalTo: superview.trailingAnchor, constant: -16),
    view.heightAnchor.constraint(equalToConstant: 44),
])

Stack views (제일 자주 쓰임)

let stack = UIStackView(arrangedSubviews: [titleLabel, subtitleLabel, button])
stack.axis = .vertical
stack.spacing = 8
stack.alignment = .fill
view.addSubview(stack)
// stack 자체만 외부 constraint

Hugging / Compression — 두 label 한 줄에

// 길어지면 잘리지 말아야 할 쪽
priceLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
nameLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
// → name 이 "..." 잘림, price 는 풀 표시

동적 height (multiline label)

descriptionLabel.numberOfLines = 0 // 무제한
// width 만 제약, height 는 알아서
descriptionLabel.widthAnchor.constraint(equalTo: view.widthAnchor, constant: -32).isActive = true

런타임 충돌 디버그

// 충돌 시 콘솔에 "Will attempt to recover by breaking constraint ..."
// 해당 constraint 에 identifier 부여 → 추적 쉬움
let c = view.heightAnchor.constraint(equalToConstant: 44)
c.identifier = "RowMinHeight"
c.isActive = true

🤔 의사결정 기준

레이아웃 권장
정렬·간격 단순 UIStackView
복잡 비율 (golden ratio 등) NSLayoutAnchor + multiplier
외부 라이브러리 OK SnapKit (가독성↑)
동적 height (table cell) label numberOfLines 0 + UITableView.automaticDimension
안전영역 / 노치 safeAreaLayoutGuide
키보드 회피 NSLayoutConstraint constant 변경 + animation

안티패턴

  • translatesAutoresizingMaskIntoConstraints 끄기 잊음: 자동 frame constraint 가 충돌. 먼저 false.
  • frame + autolayout 혼용: 한 view 는 한 모델. layoutSubviews 에서 frame 조작 시 autolayout 깨짐.
  • 모든 priority required: 첫 충돌에 앱 crash.
  • stack view 안에 0 spacing 으로 또 stack: 가독성 떨어짐. 설계 재고.
  • safeAreaLayoutGuide 무시: 노치 / Dynamic Island 위에 그림.
  • dynamic type 무시 (큰 글씨 설정): label 잘림. preferredFont(forTextStyle:) + adjustsFontForContentSizeCategory.
  • 다국어 RTL 무시: leading/trailing (NOT left/right).

🤖 LLM 활용 힌트

  • "leading/trailing 사용 (RTL 자동), top/bottom" 명시.
  • 복잡 layout 은 SnapKit 또는 Stack View first.

🔗 관련 문서