关于 mobile-ios-design
此技能指导开发者依据 Apple Human Interface Guidelines 和 SwiftUI 模式设计原生 iOS 应用界面。内容涵盖导航、适配布局、系统集成与无障碍设计。
主要功能
- 01遵循 Apple HIG 设计界面
- 02构建 SwiftUI 布局与导航
- 03适配 iPhone 和 iPad 屏幕
- 04使用 SF Symbols 与系统字体
- 05支持动态字体、深色模式和无障碍
适用场景
- 01设计符合 iOS 惯例的应用界面
- 02构建 SwiftUI 页面和导航流程
- 03为 iPhone 与 iPad 创建适配布局
- 04改善动态字体和 VoiceOver 支持
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ wshobson/ agents --skill mobile-ios-design安装后在 Claude Code 中输入/mobile-ios-design确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/hig-patterns.mdios-navigation.mdswiftui-components.md详细介绍
iOS 移动端设计
掌握 iOS Human Interface Guidelines (HIG) 和 SwiftUI 模式,构建精致、原生的 iOS 应用,让它们在 Apple 平台上自然融入。
何时使用本技能
- 遵循 Apple HIG 设计 iOS 应用界面
- 构建 SwiftUI 视图和布局
- 实现 iOS 导航模式(NavigationStack、TabView、sheet)
- 为 iPhone 和 iPad 创建自适应布局
- 使用 SF Symbols 和系统排版
- 构建无障碍的 iOS 界面
- 实现 iOS 特有的手势和交互
- 针对 Dynamic Type 和深色模式进行设计
核心概念
1. Human Interface Guidelines 原则
清晰:内容清晰易读,图标精确,装饰含蓄 尊重:UI 帮助用户理解内容,而不是与之争夺注意力 深度:视觉层次和动效传达层级关系并支持导航
平台考量:
- iOS:触控优先,紧凑显示屏,竖屏方向
- iPadOS:更大的画布,多任务处理,指针支持
- visionOS:空间计算,眼动/手势输入
2. SwiftUI 布局系统
基于堆栈的布局:
// Vertical stack with alignment
VStack(alignment: .leading, spacing: 12) {
Text("Title")
.font(.headline)
Text("Subtitle")
.font(.subheadline)
.foregroundStyle(.secondary)
}
// Horizontal stack with flexible spacing
HStack {
Image(systemName: "star.fill")
Text("Featured")
Spacer()
Text("View All")
.foregroundStyle(.blue)
}
网格布局:
// Adaptive grid that fills available width
LazyVGrid(columns: [
GridItem(.adaptive(minimum: 150, maximum: 200))
], spacing: 16) {
ForEach(items) { item in
ItemCard(item: item)
}
}
// Fixed column grid
LazyVGrid(columns: [
GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible())
], spacing: 12) {
ForEach(items) { item in
ItemThumbnail(item: item)
}
}
3. 导航模式
NavigationStack(iOS 16+):
struct ContentView: View {
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
List(items) { item in
NavigationLink(value: item) {
ItemRow(item: item)
}
}
.navigationTitle("Items")
.navigationDestination(for: Item.self) { item in
ItemDetailView(item: item)
}
}
}
}
TabView(iOS 18+):
struct MainTabView: View {
@State private var selectedTab = 0
var body: some View {
TabView(selection: $selectedTab) {
Tab("Home", systemImage: "house", value: 0) {
HomeView()
}
Tab("Search", systemImage: "magnifyingglass", value: 1) {
SearchView()
}
Tab("Profile", systemImage: "person", value: 2) {
ProfileView()
}
}
}
}
4. 系统集成
SF Symbols:
// Basic symbol
Image(systemName: "heart.fill")
.foregroundStyle(.red)
// Symbol with rendering mode
Image(systemName: "cloud.sun.fill")
.symbolRenderingMode(.multicolor)
// Variable symbol (iOS 16+)
Image(systemName: "speaker.wave.3.fill", variableValue: volume)
// Symbol effect (iOS 17+)
Image(systemName: "bell.fill")
.symbolEffect(.bounce, value: notificationCount)
Dynamic Type:
// Use semantic fonts
Text("Headline")
.font(.headline)
Text("Body text that scales with user preferences")
.font(.body)
// Custom font that respects Dynamic Type
Text("Custom")
.font(.custom("Avenir", size: 17, relativeTo: .body))
5. 视觉设计
颜色与材质:
// Semantic colors that adapt to light/dark mode
Text("Primary")
.foregroundStyle(.primary)
Text("Secondary")
.foregroundStyle(.secondary)
// System materials for blur effects
Rectangle()
.fill(.ultraThinMaterial)
.frame(height: 100)
// Vibrant materials for overlays
Text("Overlay")
.padding()
.background(.regularMaterial, in: RoundedRectangle(cornerRadius: 12))
阴影与深度:
// Standard card shadow
RoundedRectangle(cornerRadius: 16)
.fill(.background)
.shadow(color: .black.opacity(0.1), radius: 8, y: 4)
// Elevated appearance
.shadow(radius: 2, y: 1)
.shadow(radius: 8, y: 4)
快速开始组件
import SwiftUI
struct FeatureCard: View {
let title: String
let description: String
let systemImage: String
var body: some View {
HStack(spacing: 16) {
Image(systemName: systemImage)
.font(.title)
.foregroundStyle(.blue)
.frame(width: 44, height: 44)
.background(.blue.opacity(0.1), in: Circle())
VStack(alignment: .leading, spacing: 4) {
Text(title)
.font(.headline)
Text(description)
.font(.subheadline)
.foregroundStyle(.secondary)
.lineLimit(2)
}
Spacer()
Image(systemName: "chevron.right")
.foregroundStyle(.tertiary)
}
.padding()
.background(.background, in: RoundedRectangle(cornerRadius: 12))
.shadow(color: .black.opacity(0.05), radius: 4, y: 2)
}
}
最佳实践
- 使用语义化颜色:始终使用
.primary、.secondary、.background以自动支持浅色/深色模式 - 拥抱 SF Symbols:使用系统符号以保证一致性并自动获得无障碍支持
- 支持 Dynamic Type:使用语义化字体(
.body、.headline)而非固定字号 - 添加无障碍支持:包含
.accessibilityLabel()和.accessibilityHint()修饰符 - 使用安全区域:遵循
safeAreaInset,避免在屏幕边缘使用硬编码内边距 - 实现状态恢复:使用
@SceneStorage保留用户状态 - 支持 iPad 多任务处理:为分屏视图和侧拉设计
- 在真机上测试:模拟器无法完整呈现触觉反馈和性能体验
常见问题
- 布局破坏:谨慎使用
.fixedSize();优先使用灵活布局 - 性能问题:对长滚动列表使用
LazyVStack/LazyHStack - 导航缺陷:确保
NavigationLink的值符合Hashable - 深色模式问题:避免硬编码颜色;使用语义化颜色或资源目录颜色
- 无障碍失败:在启用 VoiceOver 的情况下测试
- 内存泄漏:注意闭包中的强引用循环
评论
支持 Markdown