dxe-apple-native-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseApple Native UI
Apple 原生 UI
Build and review interfaces that feel native because they use the platform's interaction, accessibility, and adaptation contracts—not because they imitate a screenshot.
构建和评审具有原生感的界面,是因为它们遵循平台在交互、无障碍和适配方面的约定,而不是通过模仿截图来实现。
Start with the target
从目标平台开始
Identify the platforms, minimum OS versions, SwiftUI versus UIKit/AppKit boundary, supported input (touch, pointer, keyboard, VoiceOver, Digital Crown, remote, eye/hand), and primary form factors. Do not apply an iPhone convention to macOS, iPad multitasking, watchOS, tvOS, or visionOS without evidence that it transfers.
Prefer system controls, semantic colors, text styles, safe-area APIs, navigation containers, and presentation APIs before custom reconstructions. Custom UI must retain the equivalent accessibility, focus, state, and cancellation behaviour.
确定目标平台、最低 OS 版本、SwiftUI 与 UIKit/AppKit 的边界、支持的输入方式(触控、指针、键盘、VoiceOver、Digital Crown、遥控器、眼动/手势)以及主要设备形态。除非有证据表明某项 iPhone 惯例可以迁移,否则不要将其套用于 macOS、iPad 多任务、watchOS、tvOS 或 visionOS。
优先使用系统控件、语义颜色、文本样式、安全区 API、导航容器和呈现 API,然后才考虑自定义实现。自定义 UI 必须保留等效的无障碍、焦点、状态和取消行为。
Fresh platform guidance
最新的平台指导
Before prescribing or implementing APIs, behaviour, design conventions, or verification that may vary by SDK or OS release, search current primary Apple sources: Apple Developer Documentation, Human Interface Guidelines, and relevant WWDC sessions. Check the project's deployment target before recommending a newer API, and distinguish current Apple guidance from repository-local compatibility constraints. The examples here express durable contracts; they are not a substitute for release-specific documentation.
在给出建议或实现可能因 SDK 或 OS 版本而异的 API、行为、设计惯例或验证方式之前,请查阅 Apple 当前的一手资料:Apple Developer Documentation、Human Interface Guidelines 以及相关 WWDC 演讲。检查项目的部署目标,再推荐更新的 API;并区分 Apple 当前指导与仓库本地的兼容性限制。此处示例表达的是长期有效的约定,不能替代针对特定版本的文档。
macOS workflow
macOS 工作流
When macOS is an intended target, read references/macos-native-workflows.md before planning, building, porting, or reviewing a non-trivial interface. It adds a Mac-specific workflow for commands, windows and documents, selection and focus, pasteboard and drag/drop, undo, state restoration, configuration, Finder interoperability, and behaviour-led verification.
Treat a Mac version as a distinct workflow even when it shares models or views with iPadOS. A resizable iPad layout is not by itself a complete Mac app.
当 macOS 是预期目标平台时,在规划、构建、移植或评审非简单界面前,请先阅读 references/macos-native-workflows.md。它补充了一套 Mac 专用工作流,涵盖命令、窗口与文档、选择与焦点、pasteboard 与拖放、撤销、状态恢复、配置、Finder 互操作性以及以行为为导向的验证。
即使与 iPadOS 共享模型或视图,也要将 Mac 版本视为独立的工作流。可调整大小的 iPad 布局本身并不能构成完整的 Mac 应用。
State and identity
状态与标识
Own state at the narrowest stable boundary. A child that only displays data receives a value; a child that edits parent state receives a binding. Keep side effects out of and give lists stable identities.
bodyswift
@Observable final class ProfileModel {
var name = ""
var isSaving = false
}
struct ProfileScreen: View {
@State private var model = ProfileModel()
var body: some View {
Form {
TextField("Name", text: $model.name)
Button("Save") { save() }
.disabled(model.name.isEmpty || model.isSaving)
}
}
}Do not turn an injected value into , use positional indices as mutable list identity, or use where , , , or another native control expresses the task.
@StateonTapGestureButtonNavigationLinkToggle将状态的所有权限定在最窄的稳定边界上。仅用于显示数据的子视图接收值;用于编辑父级状态的子视图接收 binding。避免在 中处理副作用,并为列表提供稳定标识。
bodyswift
@Observable final class ProfileModel {
var name = ""
var isSaving = false
}
struct ProfileScreen: View {
@State private var model = ProfileModel()
var body: some View {
Form {
TextField("Name", text: $model.name)
Button("Save") { save() }
.disabled(model.name.isEmpty || model.isSaving)
}
}
}不要将注入的值转为 ,不要使用位置索引作为可变列表的标识,也不要在 、、 或其他原生控件能够表达任务时使用 。
@StateButtonNavigationLinkToggleonTapGesturePlatform contracts
平台约定
- Use /
NavigationStack, sheets, alerts, confirmation dialogs, and toolbars according to the target platform. Verify back, dismiss, cancel, and focus-restoration paths.NavigationSplitView - Use semantic colors and Dynamic Type-aware typography. Test extra-large text before adding truncation, clipping, or fixed frames.
- Treat safe areas, split view, window resizing, rotation, external keyboard, pointer, and layout direction as input to the layout—not exceptional breakpoints.
- Prefer ,
@Observable,@State, and@Bindingwhere deployment targets permit; gate version-specific APIs and provide a real fallback.@Bindable - Make animations value-driven and task-preserving under Reduce Motion. Wait for the observable end state before testing or reporting it.
- 根据目标平台使用 /
NavigationStack、sheet、alert、confirmation dialog 和 toolbar。验证返回、关闭、取消和焦点恢复路径。NavigationSplitView - 使用语义颜色和支持 Dynamic Type 的排版。在添加截断、裁剪或固定尺寸之前,先测试超大文本。
- 将安全区、分屏、窗口缩放、旋转、外接键盘、指针和布局方向视为布局的输入条件,而非特殊断点。
- 在部署目标允许时优先使用 、
@Observable、@State和@Binding;为特定版本的 API 设置版本门槛,并提供真正可用的回退方案。@Bindable - 让动画由值驱动,并在启用 Reduce Motion 时保留任务语义。测试或报告前,等待可观察的最终状态。
Accessibility
无障碍
Accessibility is expressed through the native accessibility tree, not ARIA. Check VoiceOver labels, values, hints, traits, grouping, reading order, adjustable actions, focus movement, and disabled controls. Hide decorative imagery; label meaningful images and ambiguous icons.
swift
Button(action: play) {
Image(systemName: "play.fill")
}
.accessibilityLabel("Play preview")
Image(systemName: "sparkles")
.accessibilityHidden(true)Read references/apple-verification.md for simulator, device, XCUITest, accessibility, and form-factor evidence. Read it before making native verification claims.
无障碍能力通过原生无障碍树实现,而不是通过 ARIA 实现。检查 VoiceOver 标签、值、提示、traits、分组、阅读顺序、可调整操作、焦点移动和禁用控件。隐藏纯装饰图像;为有意义的图像和含义不明确的图标添加标签。
swift
Button(action: play) {
Image(systemName: "play.fill")
}
.accessibilityLabel("Play preview")
Image(systemName: "sparkles")
.accessibilityHidden(true)阅读 references/apple-verification.md,了解模拟器、真机、XCUITest、无障碍和设备形态方面的验证依据。在声称已完成原生验证之前,请先阅读该文档。
Review output
评审输出
Anchor findings to a source path or an observed target/device. State whether evidence is source-only or rendered. Name the affected platform and input method; an iOS finding is not automatically a macOS finding.
将发现的问题定位到源路径或实际观察到的目标/设备。明确说明证据是仅来自源码,还是来自实际渲染。指出受影响的平台和输入方式;iOS 上的发现不会自动等同于 macOS 上的发现。
Prefer / reject
优先采用 / 应避免
| Prefer | Reject |
|---|---|
| System control with intentional styling | Clickable stacks or images standing in for controls |
| Semantic fonts, colors, and adaptive layout | Fixed dimensions that break at larger text or smaller windows |
| Stable IDs and explicit state ownership | Index identity and effects hidden in |
| Platform-specific verification | Treating a simulator screenshot as proof for every target |
| Version gates with useful fallbacks | Unconditional new APIs that silently drop supported users |
| 优先采用 | 应避免 |
|---|---|
| 经过有意设计的系统控件 | 用可点击的堆栈或图片代替控件 |
| 语义字体、颜色和自适应布局 | 在大字号或小窗口下失效的固定尺寸 |
| 稳定 ID 和明确的状态归属 | 索引标识以及隐藏在 |
| 平台特定的验证 | 将模拟器截图视为所有目标的证据 |
| 带版本门槛且有实用回退方案 | 无条件使用新 API,导致受支持的用户被静默排除 |