ios-design
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseApple SwiftUI iOS Design Best Practices
Apple SwiftUI iOS 设计最佳实践
Comprehensive guide for building Apple-quality iOS UIs with SwiftUI. Contains 62 rules across 8 categories covering design systems, state management, layout, view composition, navigation, components, accessibility, and animation polish.
这是一份使用SwiftUI构建Apple级iOS UI的综合指南,包含8个类别共62条规则,覆盖设计系统、状态管理、布局、视图组合、导航、组件、无障碍访问和动画优化。
When to Apply
适用场景
Reference these guidelines when:
- Building new SwiftUI views and screens
- Implementing design systems with semantic colors, typography, and spacing
- Managing state with @State, @Binding, @Observable, @Environment
- Laying out content with stacks, grids, and adaptive layouts
- Composing views with @ViewBuilder and custom modifiers
- Implementing navigation with NavigationStack, TabView, sheets
- Choosing and configuring SwiftUI components
- Ensuring VoiceOver support, touch targets, and reduce motion
- Adding semantic transitions and loading state animations
在以下场景中可参考本指南:
- 构建新的SwiftUI视图和屏幕
- 实现包含语义化颜色、排版和间距的设计系统
- 使用@State、@Binding、@Observable、@Environment管理状态
- 使用栈、网格和自适应布局排布内容
- 使用@ViewBuilder和自定义修饰符组合视图
- 使用NavigationStack、TabView、sheets实现导航
- 选择和配置SwiftUI组件
- 确保VoiceOver支持、触摸目标适配和减少动画适配
- 添加语义化过渡和加载状态动画
Rule Categories by Priority
按优先级划分的规则类别
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Design System | CRITICAL | |
| 2 | State & Data Flow | CRITICAL | |
| 3 | Layout & Sizing | HIGH | |
| 4 | View Composition | HIGH | |
| 5 | Navigation | HIGH | |
| 6 | Components & Controls | HIGH | |
| 7 | Accessibility | HIGH | |
| 8 | Animation & Polish | MEDIUM | |
| 优先级 | 类别 | 影响级别 | 前缀 |
|---|---|---|---|
| 1 | 设计系统 | 关键 | |
| 2 | 状态与数据流 | 关键 | |
| 3 | 布局与尺寸 | 高 | |
| 4 | 视图组合 | 高 | |
| 5 | 导航 | 高 | |
| 6 | 组件与控件 | 高 | |
| 7 | 无障碍访问 | 高 | |
| 8 | 动画与优化 | 中 | |
Quick Reference
快速参考
1. Design System (CRITICAL)
1. 设计系统(关键)
- - Use semantic and system colors
design-semantic-colors - - Use system typography styles
design-typography - - Establish clear visual hierarchy
design-visual-hierarchy - - Support Dark Mode from day one
design-dark-mode - - Use material backgrounds for depth
design-material-backgrounds - - Use SF Symbols for consistent iconography
design-sf-symbols - - Respect safe areas for content layout
design-safe-areas - - Apply gradients for visual depth
design-gradients - - Use foregroundStyle over foregroundColor
design-foreground-style
- - 使用语义化和系统颜色
design-semantic-colors - - 使用系统排版样式
design-typography - - 建立清晰的视觉层级
design-visual-hierarchy - - 从一开始就支持深色模式
design-dark-mode - - 使用材质背景增加层次感
design-material-backgrounds - - 使用SF Symbols实现一致的图标系统
design-sf-symbols - - 内容布局时遵循安全区域规则
design-safe-areas - - 应用渐变增加视觉深度
design-gradients - - 使用foregroundStyle替代foregroundColor
design-foreground-style
2. State & Data Flow (CRITICAL)
2. 状态与数据流(关键)
- - Use @State for view-local value types
state-local - - Use @Binding for child view mutations
state-binding - - Use @Environment for shared app data
state-environment - - Use @Observable for model classes
state-observable - - Avoid creating state inside view body
state-avoid-in-body - - Minimize state scope to reduce re-renders
state-minimize-scope - - Use @Bindable for @Observable bindings
state-bindable
- - 对视图本地值类型使用@State
state-local - - 对子视图修改使用@Binding
state-binding - - 对共享应用数据使用@Environment
state-environment - - 对模型类使用@Observable
state-observable - - 避免在视图body内部创建状态
state-avoid-in-body - - 最小化作用域以减少重渲染
state-minimize-scope - - 对@Observable绑定使用@Bindable
state-bindable
3. Layout & Sizing (HIGH)
3. 布局与尺寸(高)
- - Use 8pt grid for spacing
layout-8pt-grid - - Constrain text to readable width on iPad
layout-readable-width - - Use adaptive layouts for different size classes
layout-adaptive - - Use system standard margins
layout-standard-margins - - Show scroll indicators for long content
layout-scroll-indicators - - Use stacks instead of manual positioning
layout-stacks - - Configure stack alignment and spacing
layout-stack-config - - Use Spacer for flexible distribution
layout-spacer - - Use frame() for explicit size constraints
layout-frame-sizing - - Use ZStack for layered view composition
layout-zstack - - Use Grid for aligned tabular layouts
layout-grid - - Use LazyVGrid for scrollable grid layouts
layout-lazy-grids
- - 使用8pt网格规范设置间距
layout-8pt-grid - - 在iPad上限制文本为可读宽度
layout-readable-width - - 针对不同尺寸类使用自适应布局
layout-adaptive - - 使用系统标准边距
layout-standard-margins - - 长内容时显示滚动指示器
layout-scroll-indicators - - 使用栈而非手动定位
layout-stacks - - 配置栈的对齐方式和间距
layout-stack-config - - 使用Spacer实现灵活分布
layout-spacer - - 使用frame()设置显式尺寸约束
layout-frame-sizing - - 使用ZStack实现分层视图组合
layout-zstack - - 使用Grid实现对齐的表格布局
layout-grid - - 使用LazyVGrid实现可滚动网格布局
layout-lazy-grids
4. View Composition (HIGH)
4. 视图组合(高)
- - Return some View from body property
view-body-some-view - - Use properties to make views configurable
view-custom-properties - - Apply modifiers in correct order
view-modifier-order - - Use @ViewBuilder for flexible composition
view-viewbuilder - - Prefer value types for view data
view-prefer-value-types - - Prefer composition over inheritance
view-prefer-composition
- - 从body属性返回some View
view-body-some-view - - 使用属性让视图可配置
view-custom-properties - - 按正确顺序应用修饰符
view-modifier-order - - 使用@ViewBuilder实现灵活组合
view-viewbuilder - - 优先使用值类型存储视图数据
view-prefer-value-types - - 优先使用组合而非继承
view-prefer-composition
5. Navigation (HIGH)
5. 导航(高)
- - Use NavigationStack for modern navigation
nav-navigationstack - - Organize app sections with TabView
nav-tabview - - Use item binding for sheet presentation
nav-sheet-item - - Use environment dismiss for modal closure
nav-dismiss - - Place toolbar items correctly
nav-toolbar - - Use tab bar for top-level navigation
nav-tab-bar - - Configure navigation bar
nav-bar - - Design clear navigation hierarchy
nav-hierarchy - - Integrate search using searchable modifier
nav-search
- - 使用NavigationStack实现现代导航
nav-navigationstack - - 使用TabView组织应用板块
nav-tabview - - 使用item绑定呈现sheet
nav-sheet-item - - 使用环境dismiss关闭模态视图
nav-dismiss - - 正确放置工具栏项目
nav-toolbar - - 使用标签栏实现顶级导航
nav-tab-bar - - 配置导航栏
nav-bar - - 设计清晰的导航层级
nav-hierarchy - - 使用searchable修饰符集成搜索
nav-search
6. Components & Controls (HIGH)
6. 组件与控件(高)
- - Choose List vs LazyVStack by feature needs
comp-list-vs-lazyvstack - - Choose sheet vs fullScreenCover
comp-sheet-vs-fullscreen - - Choose the right picker style
comp-picker - - Choose Grid vs LazyVGrid by data size
comp-grid-vs-lazygrid - - Configure text input components
comp-textfield - - Use appropriate button styles
comp-button - - Design list cells with standard layouts
comp-list-cells - - Use alerts sparingly for critical information
comp-alerts - - Use action sheets for contextual choices
comp-action-sheets - - Use segmented controls for exclusive options
comp-segmented - - Use menus for secondary actions
comp-menus - - Use ContentUnavailableView for empty states
comp-content-unavailable
- - 根据功能需求选择List或LazyVStack
comp-list-vs-lazyvstack - - 选择sheet或fullScreenCover
comp-sheet-vs-fullscreen - - 选择合适的选择器样式
comp-picker - - 根据数据量选择Grid或LazyVGrid
comp-grid-vs-lazygrid - - 配置文本输入组件
comp-textfield - - 使用合适的按钮样式
comp-button - - 使用标准布局设计列表单元格
comp-list-cells - - 仅在关键信息场景下使用提醒
comp-alerts - - 使用操作表处理上下文选项
comp-action-sheets - - 使用分段控件处理互斥选项
comp-segmented - - 使用菜单处理次要操作
comp-menus - - 使用ContentUnavailableView处理空状态
comp-content-unavailable
7. Accessibility (HIGH)
7. 无障碍访问(高)
- - Add VoiceOver labels to interactive elements
access-voiceover-labels - - Ensure minimum 44pt touch targets
access-touch-targets - - Respect reduce motion preference
access-reduce-motion
- - 为交互元素添加VoiceOver标签
access-voiceover-labels - - 确保最小44pt的触摸目标
access-touch-targets - - 遵循减少动画的偏好设置
access-reduce-motion
8. Animation & Polish (MEDIUM)
8. 动画与优化(中)
- - Use semantic transitions for appearing views
anim-transitions - - Animate loading and empty states
anim-loading-states - - Use withAnimation for explicit state changes
anim-with-animation - - Use matchedGeometryEffect for smooth view transitions
anim-matched-geometry
- - 为出现的视图使用语义化过渡
anim-transitions - - 为加载和空状态添加动画
anim-loading-states - - 使用withAnimation处理显式状态变更
anim-with-animation - - 使用matchedGeometryEffect实现平滑视图过渡
anim-matched-geometry
How to Use
使用方法
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
阅读单个参考文件获取详细说明和代码示例:
- Section definitions - 类别结构和影响级别说明
- Rule template - 添加新规则的模板
Reference Files
参考文件
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| 文件 | 描述 |
|---|---|
| references/_sections.md | 类别定义与排序 |
| assets/templates/_template.md | 新规则模板 |