ios-application-dev

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

iOS 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

PurposeComponent
Main sections
UITabBarController
Drill-down
UINavigationController
Focused taskSheet 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 modeSemantic colors (
.systemBackground
,
.label
)
PermissionsContextual request +
AVCaptureDevice
Lifecycle
UIApplication
notifications
用途组件
主要分区
UITabBarController
深度导航
UINavigationController
聚焦任务表单展示
关键选择
UIAlertController
次要操作
UIContextMenuInteraction
列表内容
UICollectionView
+
DiffableDataSource
分区列表
DiffableDataSource
+
headerMode
网格布局
UICollectionViewCompositionalLayout
搜索
UISearchController
分享
UIActivityViewController
单次定位
CLLocationButton
反馈
UIImpactFeedbackGenerator
线性布局
UIStackView
自定义形状
CAShapeLayer
+
UIBezierPath
渐变
CAGradientLayer
现代按钮
UIButton.Configuration
动态文本
UIFontMetrics
+
preferredFont
Dark Mode语义颜色(
.systemBackground
,
.label
权限上下文请求 +
AVCaptureDevice
生命周期
UIApplication
通知

SwiftUI

SwiftUI

PurposeComponent
Main sections
TabView
+
tabItem
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)
用途组件
主要分区
TabView
+
tabItem
深度导航
NavigationStack
+
NavigationPath
聚焦任务
.sheet
+
presentationDetents
关键选择
.alert
次要操作
.contextMenu
列表内容
List
+
.insetGrouped
搜索
.searchable
分享
ShareLink
单次定位
LocationButton
反馈
UIImpactFeedbackGenerator
已知进度
ProgressView(value:total:)
未知进度
ProgressView()
动态文本
.font(.body)
语义样式
Dark Mode
.primary
,
.secondary
,
Color(.systemBackground)
场景生命周期
@Environment(\.scenePhase)
减少动态效果
@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)
  • 触摸目标 ≥ 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:
    UIFontMetrics
    /
    Font.custom(_:size:relativeTo:)
  • Adapt layout at accessibility sizes (minimum 11pt)
  • UIKit:
    preferredFont(forTextStyle:)
    +
    adjustsFontForContentSizeCategory = true
  • SwiftUI:语义文本样式
    .headline
    ,
    .body
    ,
    .caption
  • 自定义字体:
    UIFontMetrics
    /
    Font.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
    .destructive
    role
  • 仅在关键决策时使用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

参考资料

TopicReference
Touch Targets, Safe Area, CollectionViewLayout System
TabBar, NavigationController, ModalNavigation Patterns
StackView, Button, Alert, Search, ContextMenuUIKit Components
CAShapeLayer, CAGradientLayer, Core AnimationGraphics & Animation
Dynamic Type, Semantic Colors, VoiceOverAccessibility
Permissions, Location, Share, Lifecycle, HapticsSystem Integration
Metal Shaders & GPUMetal Shader Reference
SwiftUI HIG, Components, Patterns, Anti-PatternsSwiftUI Design Guidelines
Optionals, Protocols, async/await, ARC, Error HandlingSwift 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着色器与GPUMetal着色器参考
SwiftUI HIG、组件、模式、反模式SwiftUI设计准则
可选类型、协议、async/await、ARC、错误处理Swift编码规范

Swift、SwiftUI、UIKit、SF Symbols、Metal和Apple是Apple Inc.的商标。SnapKit是其各自所有者的商标。