iOS Application Development Guide
A practical guide for building iOS applications using UIKit, SnapKit, and SwiftUI. Focuses on proven patterns and Apple platform conventions.
Quick Reference
UIKit
| Purpose | Component |
|---|
| Main sections | INLINECODE0 |
| Drill-down |
UINavigationController |
| Focused task | Sheet presentation |
| Critical choice |
UIAlertController |
| Secondary actions |
UIContextMenuInteraction |
| List content |
UICollectionView +
DiffableDataSource |
| Sectioned list |
DiffableDataSource +
headerMode |
| Grid layout |
UICollectionViewCompositionalLayout |
| Search |
UISearchController |
| Share |
UIActivityViewController |
| Location (once) |
CLLocationButton |
| Feedback |
UIImpactFeedbackGenerator |
| Linear layout |
UIStackView |
| Custom shapes |
CAShapeLayer +
UIBezierPath |
| Gradients |
CAGradientLayer |
| Modern buttons |
UIButton.Configuration |
| Dynamic text |
UIFontMetrics +
preferredFont |
| Dark mode | Semantic colors (
.systemBackground,
.label) |
| Permissions | Contextual request +
AVCaptureDevice |
| Lifecycle |
UIApplication notifications |
SwiftUI
| Purpose | Component |
|---|
| Main sections | INLINECODE24 + INLINECODE25 |
| Drill-down |
NavigationStack +
NavigationPath |
| Focused task |
.sheet +
presentationDetents |
| Critical choice |
.alert |
| Secondary actions |
.contextMenu |
| List content |
List +
.insetGrouped |
| Search |
.searchable |
| Share |
ShareLink |
| Location (once) |
LocationButton |
| Feedback |
UIImpactFeedbackGenerator |
| Progress (known) |
ProgressView(value:total:) |
| Progress (unknown) |
ProgressView() |
| Dynamic text |
.font(.body) semantic styles |
| Dark mode |
.primary,
.secondary,
Color(.systemBackground) |
| Scene lifecycle |
@Environment(\.scenePhase) |
| Reduce motion |
@Environment(\.accessibilityReduceMotion) |
| Dynamic type |
@Environment(\.dynamicTypeSize) |
Core Principles
Layout
- - Touch targets >= 44pt
- Content within safe areas (SwiftUI respects by default, use
.ignoresSafeArea() only for backgrounds) - 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)
Typography
- - UIKit:
preferredFont(forTextStyle:) + INLINECODE49 - SwiftUI: semantic text styles
.headline, .body, INLINECODE52 - Custom fonts:
UIFontMetrics / INLINECODE54 - Adapt layout at accessibility sizes (minimum 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
Accessibility
- - Labels on icon buttons (
.accessibilityLabel()) - Reduce motion respected (
@Environment(\.accessibilityReduceMotion)) - Logical reading order (
.accessibilitySortPriority()) - Support Bold Text, Increase Contrast preferences
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
Privacy & Permissions
- - Request permissions in context (not at launch)
- Custom explanation before system dialog
- Support Sign in with Apple
- Respect ATT denial
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
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
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
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
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
Components
- - [ ] Alerts for critical decisions only
- [ ] Sheets have dismiss path (button and/or swipe)
- [ ] List rows >= 44pt tall
- [ ] Destructive buttons use
.destructive role
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
System Integration
- - [ ] App handles interruptions gracefully (calls, background, Siri)
- [ ] App content indexed for Spotlight
- [ ] Share Sheet available for shareable content
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.
iOS应用开发指南
使用UIKit、SnapKit和SwiftUI构建iOS应用的实用指南。专注于经过验证的模式和苹果平台惯例。
快速参考
UIKit
| 用途 | 组件 |
|---|
| 主要分区 | UITabBarController |
| 层级导航 |
UINavigationController |
| 聚焦任务 | 表单展示 |
| 关键选择 | UIAlertController |
| 次要操作 | UIContextMenuInteraction |
| 列表内容 | UICollectionView + DiffableDataSource |
| 分区列表 | DiffableDataSource + headerMode |
| 网格布局 | UICollectionViewCompositionalLayout |
| 搜索 | UISearchController |
| 分享 | UIActivityViewController |
| 位置(单次) | CLLocationButton |
| 反馈 | UIImpactFeedbackGenerator |
| 线性布局 | UIStackView |
| 自定义形状 | CAShapeLayer + UIBezierPath |
| 渐变 | CAGradientLayer |
| 现代按钮 | UIButton.Configuration |
| 动态文本 | UIFontMetrics + preferredFont |
| 深色模式 | 语义颜色(.systemBackground、.label) |
| 权限 | 上下文请求 + AVCaptureDevice |
| 生命周期 | UIApplication 通知 |
SwiftUI
| 用途 | 组件 |
|---|
| 主要分区 | TabView + tabItem |
| 层级导航 |
NavigationStack + NavigationPath |
| 聚焦任务 | .sheet + presentationDetents |
| 关键选择 | .alert |
| 次要操作 | .contextMenu |
| 列表内容 | List + .insetGrouped |
| 搜索 | .searchable |
| 分享 | ShareLink |
| 位置(单次) | LocationButton |
| 反馈 | UIImpactFeedbackGenerator |
| 进度(已知) | ProgressView(value:total:) |
| 进度(未知) | ProgressView() |
| 动态文本 | .font(.body) 语义样式 |
| 深色模式 | .primary、.secondary、Color(.systemBackground) |
| 场景生命周期 | @Environment(\.scenePhase) |
| 减少动效 | @Environment(\.accessibilityReduceMotion) |
| 动态类型 | @Environment(\.dynamicTypeSize) |
核心原则
布局
- - 触摸目标 >= 44pt
- 内容在安全区域内(SwiftUI默认遵守,仅背景使用.ignoresSafeArea())
- 使用8pt间距增量(8、16、24、32、40、48)
- 主要操作在拇指区域
- 支持所有屏幕尺寸(iPhone SE 375pt 到 Pro Max 430pt)
排版
- - UIKit:preferredFont(forTextStyle:) + adjustsFontForContentSizeCategory = true
- SwiftUI:语义文本样式 .headline、.body、.caption
- 自定义字体:UIFontMetrics / Font.custom(_:size:relativeTo:)
- 在无障碍尺寸下调整布局(最小11pt)
颜色
- - 使用语义系统颜色(.systemBackground、.label、.primary、.secondary)
- 自定义颜色的资源目录变体(任意/深色外观)
- 无纯颜色信息(配合图标或文字)
- 普通文本对比度 >= 4.5:1,大文本3:1
无障碍
- - 图标按钮的标签(.accessibilityLabel())
- 尊重减少动效(@Environment(\.accessibilityReduceMotion))
- 逻辑阅读顺序(.accessibilitySortPriority())
- 支持粗体文本、增加对比度偏好
导航
- - 标签栏(3-5个分区)在导航期间保持可见
- 返回滑动有效(切勿覆盖系统手势)
- 跨标签页保持状态(@SceneStorage、@State)
- 切勿使用汉堡菜单
隐私与权限
- - 在上下文中请求权限(非启动时)
- 系统对话框前提供自定义说明
- 支持通过Apple登录
- 尊重ATT拒绝
检查清单
布局
- - [ ] 触摸目标 >= 44pt
- [ ] 内容在安全区域内
- [ ] 主要操作在拇指区域(下半部分)
- [ ] 灵活宽度适配所有屏幕尺寸(SE到Pro Max)
- [ ] 间距对齐8pt网格
排版
- - [ ] 语义文本样式或UIFontMetrics缩放的自定义字体
- [ ] 动态类型支持到无障碍尺寸
- [ ] 大尺寸时布局重新排列(无截断)
- [ ] 最小文本尺寸11pt
颜色
- - [ ] 语义系统颜色或浅色/深色资源变体
- [ ] 深色模式是设计意图(非简单反转)
- [ ] 无纯颜色信息
- [ ] 文本对比度 >= 4.5:1(普通)/ 3:1(大文本)
- [ ] 交互元素使用单一强调色
无障碍
- - [ ] 所有交互元素有VoiceOver标签
- [ ] 逻辑阅读顺序
- [ ] 尊重粗体文本偏好
- [ ] 减少动效禁用装饰性动画
- [ ] 所有手势有替代访问路径
导航
- - [ ] 3-5个顶级分区的标签栏
- [ ] 无汉堡/抽屉菜单
- [ ] 导航期间标签栏保持可见
- [ ] 返回滑动全程有效
- [ ] 跨标签页保持状态
组件
- - [ ] 仅关键决策使用警告
- [ ] 表单有关闭路径(按钮和/或滑动)
- [ ] 列表行高 >= 44pt
- [ ] 破坏性按钮使用.destructive角色
隐私
- - [ ] 在上下文中请求权限(非启动时)
- [ ] 系统权限对话框前提供自定义说明
- [ ] 与其他提供商一起提供通过Apple登录
- [ ] 基本功能无需账户即可使用
- [ ] 如需追踪则显示ATT提示,尊重拒绝
系统集成
- - [ ] 应用优雅处理中断(电话、后台、Siri)
- [ ] 应用内容为Spotlight建立索引
- [ ] 可分享内容提供分享表单
参考
| 主题 | 参考 |
|---|
| 触摸目标、安全区域、CollectionView | 布局系统 |
| TabBar、NavigationController、Modal |
导航模式 |
| StackView、Button、Alert、Search、ContextMenu |
UIKit组件 |
| CAShapeLayer、CAGradientLayer、Core Animation |
图形与动画 |
| 动态类型、语义颜色、VoiceOver |
无障碍 |
| 权限、位置、分享、生命周期、触觉反馈 |
系统集成 |
| Metal着色器与GPU |
Metal着色器参考 |
| SwiftUI HIG、组件、模式、反模式 |
SwiftUI设计指南 |
| 可选值、协议、async/await、ARC、错误处理 |
Swift编码标准 |
Swift、SwiftUI、UIKit、SF Symbols、Metal和Apple是Apple Inc.的商标。SnapKit是其各自所有者的商标。