ios-application-dev
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseiOS Application Development Guide
iOS应用开发指南
A practical guide for building iOS applications using UIKit, SnapKit, and SwiftUI. Focuses on proven patterns and Apple platform conventions.
这是一份使用UIKit、SnapKit和SwiftUI构建iOS应用的实用指南,重点介绍经过验证的模式和Apple平台规范。
Quick Reference
快速参考
UIKit
UIKit
| Purpose | Component |
|---|---|
| Main sections | |
| Drill-down | |
| Focused task | Sheet presentation |
| Critical choice | |
| Secondary actions | |
| List content | |
| Sectioned list | |
| Grid layout | |
| Search | |
| Share | |
| Location (once) | |
| Feedback | |
| Linear layout | |
| Custom shapes | |
| Gradients | |
| Modern buttons | |
| Dynamic text | |
| Dark mode | Semantic colors ( |
| Permissions | Contextual request + |
| Lifecycle | |
| 用途 | 组件 |
|---|---|
| 主要分区 | |
| 深度导航 | |
| 聚焦任务 | 表单展示 |
| 关键选择 | |
| 次要操作 | |
| 列表内容 | |
| 分区列表 | |
| 网格布局 | |
| 搜索 | |
| 分享 | |
| 单次定位 | |
| 反馈 | |
| 线性布局 | |
| 自定义形状 | |
| 渐变 | |
| 现代按钮 | |
| 动态文本 | |
| Dark Mode | 语义颜色( |
| 权限 | 上下文请求 + |
| 生命周期 | |
SwiftUI
SwiftUI
| Purpose | Component |
|---|---|
| Main sections | |
| Drill-down | |
| Focused task | |
| Critical choice | |
| Secondary actions | |
| List content | |
| Search | |
| Share | |
| Location (once) | |
| Feedback | |
| Progress (known) | |
| Progress (unknown) | |
| Dynamic text | |
| Dark mode | |
| Scene lifecycle | |
| Reduce motion | |
| Dynamic type | |
| 用途 | 组件 |
|---|---|
| 主要分区 | |
| 深度导航 | |
| 聚焦任务 | |
| 关键选择 | |
| 次要操作 | |
| 列表内容 | |
| 搜索 | |
| 分享 | |
| 单次定位 | |
| 反馈 | |
| 已知进度 | |
| 未知进度 | |
| 动态文本 | |
| Dark Mode | |
| 场景生命周期 | |
| 减少动态效果 | |
| Dynamic Type | |
Core Principles
核心原则
Layout
布局
- Touch targets >= 44pt
- Content within safe areas (SwiftUI respects by default, use only for backgrounds)
.ignoresSafeArea() - Use 8pt spacing increments (8, 16, 24, 32, 40, 48)
- Primary actions in thumb zone
- Support all screen sizes (iPhone SE 375pt to Pro Max 430pt)
- 触摸目标 ≥ 44pt
- 内容位于安全区域内(SwiftUI默认遵循,仅背景使用)
.ignoresSafeArea() - 使用8pt增量的间距(8、16、24、32、40、48)
- 主要操作位于拇指可达区域
- 支持所有屏幕尺寸(iPhone SE 375pt 至 Pro Max 430pt)
Typography
排版
- UIKit: +
preferredFont(forTextStyle:)adjustsFontForContentSizeCategory = true - SwiftUI: semantic text styles ,
.headline,.body.caption - Custom fonts: /
UIFontMetricsFont.custom(_:size:relativeTo:) - Adapt layout at accessibility sizes (minimum 11pt)
- UIKit:+
preferredFont(forTextStyle:)adjustsFontForContentSizeCategory = true - SwiftUI:语义文本样式 ,
.headline,.body.caption - 自定义字体:/
UIFontMetricsFont.custom(_:size:relativeTo:) - 在无障碍尺寸下适配布局(最小11pt)
Colors
颜色
- Use semantic system colors (,
.systemBackground,.label,.primary).secondary - Asset catalog variants for custom colors (Any/Dark Appearance)
- No color-only information (pair with icons or text)
- Contrast ratio >= 4.5:1 for normal text, 3:1 for large text
- 使用语义系统颜色(,
.systemBackground,.label,.primary).secondary - 自定义颜色使用资源目录变体(任意/深色外观)
- 不使用仅依赖颜色传递的信息(搭配图标或文本)
- 普通文本对比度 ≥ 4.5:1,大文本对比度 ≥ 3:1
Accessibility
无障碍功能
- Labels on icon buttons ()
.accessibilityLabel() - Reduce motion respected ()
@Environment(\.accessibilityReduceMotion) - Logical reading order ()
.accessibilitySortPriority() - Support Bold Text, Increase Contrast preferences
- 图标按钮添加标签()
.accessibilityLabel() - 遵循减少动态效果设置()
@Environment(\.accessibilityReduceMotion) - 合理的阅读顺序()
.accessibilitySortPriority() - 支持粗体文本、增强对比度偏好设置
Navigation
导航
- Tab bar (3-5 sections) stays visible during navigation
- Back swipe works (never override system gestures)
- State preserved across tabs (,
@SceneStorage)@State - Never use hamburger menus
- 标签栏(3-5个分区)在导航期间保持可见
- 返回滑动手势可用(切勿覆盖系统手势)
- 跨标签保留状态(,
@SceneStorage)@State - 绝不使用汉堡菜单
Privacy & Permissions
隐私与权限
- Request permissions in context (not at launch)
- Custom explanation before system dialog
- Support Sign in with Apple
- Respect ATT denial
- 在上下文场景中请求权限(而非启动时)
- 系统对话框前显示自定义说明
- 支持通过Apple登录
- 尊重ATT拒绝请求
Checklist
检查清单
Layout
布局
- Touch targets >= 44pt
- Content within safe areas
- Primary actions in thumb zone (bottom half)
- Flexible widths for all screen sizes (SE to Pro Max)
- Spacing aligns to 8pt grid
- 触摸目标 ≥ 44pt
- 内容位于安全区域内
- 主要操作位于拇指可达区域(下半部分)
- 适配所有屏幕尺寸的灵活宽度(SE至Pro Max)
- 间距对齐8pt网格
Typography
排版
- Semantic text styles or UIFontMetrics-scaled custom fonts
- Dynamic Type supported up to accessibility sizes
- Layouts reflow at large sizes (no truncation)
- Minimum text size 11pt
- 使用语义文本样式或UIFontMetrics缩放的自定义字体
- 支持Dynamic Type直至无障碍尺寸
- 大尺寸下布局自动重排(无截断)
- 最小文本尺寸11pt
Colors
颜色
- Semantic system colors or light/dark asset variants
- Dark Mode is intentional (not just inverted)
- No color-only information
- Text contrast >= 4.5:1 (normal) / 3:1 (large)
- Single accent color for interactive elements
- 使用语义系统颜色或明/暗资源变体
- Dark Mode为有意设计(而非仅反转颜色)
- 不使用仅依赖颜色传递的信息
- 文本对比度 ≥ 4.5:1(普通)/3:1(大文本)
- 交互元素使用单一强调色
Accessibility
无障碍功能
- VoiceOver labels on all interactive elements
- Logical reading order
- Bold Text preference respected
- Reduce Motion disables decorative animations
- All gestures have alternative access paths
- 所有交互元素添加VoiceOver标签
- 合理的阅读顺序
- 遵循粗体文本偏好设置
- 减少动态效果时禁用装饰性动画
- 所有手势都有替代访问路径
Navigation
导航
- Tab bar for 3-5 top-level sections
- No hamburger/drawer menus
- Tab bar stays visible during navigation
- Back swipe works throughout
- State preserved across tabs
- 标签栏用于3-5个顶级分区
- 不使用汉堡/抽屉菜单
- 标签栏在导航期间保持可见
- 返回滑动手势全程可用
- 跨标签保留状态
Components
组件
- Alerts for critical decisions only
- Sheets have dismiss path (button and/or swipe)
- List rows >= 44pt tall
- Destructive buttons use role
.destructive
- 仅在关键决策时使用Alerts
- 表单有关闭路径(按钮和/或滑动)
- 列表行高度 ≥ 44pt
- 破坏性按钮使用角色
.destructive
Privacy
隐私
- Permissions requested in context (not at launch)
- Custom explanation before system permission dialog
- Sign in with Apple offered with other providers
- Basic features usable without account
- ATT prompt shown if tracking, denial respected
- 在上下文场景中请求权限(而非启动时)
- 系统权限对话框前显示自定义说明
- 与其他登录提供商一同提供通过Apple登录选项
- 无需账户即可使用基础功能
- 如需跟踪则显示ATT提示,尊重拒绝请求
System Integration
系统集成
- App handles interruptions gracefully (calls, background, Siri)
- App content indexed for Spotlight
- Share Sheet available for shareable content
- 应用可优雅处理中断(来电、后台、Siri)
- 应用内容可被Spotlight索引
- 可分享内容支持分享表单
References
参考资料
| Topic | Reference |
|---|---|
| Touch Targets, Safe Area, CollectionView | Layout System |
| TabBar, NavigationController, Modal | Navigation Patterns |
| StackView, Button, Alert, Search, ContextMenu | UIKit Components |
| CAShapeLayer, CAGradientLayer, Core Animation | Graphics & Animation |
| Dynamic Type, Semantic Colors, VoiceOver | Accessibility |
| Permissions, Location, Share, Lifecycle, Haptics | System Integration |
| Metal Shaders & GPU | Metal Shader Reference |
| SwiftUI HIG, Components, Patterns, Anti-Patterns | SwiftUI Design Guidelines |
| Optionals, Protocols, async/await, ARC, Error Handling | Swift Coding Standards |
Swift, SwiftUI, UIKit, SF Symbols, Metal, and Apple are trademarks of Apple Inc. SnapKit is a trademark of its respective owners.
| 主题 | 参考链接 |
|---|---|
| 触摸目标、安全区域、集合视图 | 布局系统 |
| 标签栏、导航控制器、模态视图 | 导航模式 |
| 栈视图、按钮、警告、搜索、上下文菜单 | UIKit组件 |
| CAShapeLayer、CAGradientLayer、核心动画 | 图形与动画 |
| Dynamic Type、语义颜色、VoiceOver | 无障碍功能 |
| 权限、定位、分享、生命周期、触觉反馈 | 系统集成 |
| Metal着色器与GPU | Metal着色器参考 |
| SwiftUI HIG、组件、模式、反模式 | SwiftUI设计准则 |
| 可选类型、协议、async/await、ARC、错误处理 | Swift编码规范 |
Swift、SwiftUI、UIKit、SF Symbols、Metal和Apple是Apple Inc.的商标。SnapKit是其各自所有者的商标。