如何在Apple Watch的SwiftUI modal sheet中添加符合HIG规范的图片?求示例
watchOS 带图片模态面板实现示例(符合HIG规范)

以下是SwiftUI版本的可直接运行实现代码:
import SwiftUI struct MainView: View { @State private var isModalPresented = false var body: some View { Button("唤起模态面板") { isModalPresented = true } .sheet(isPresented: $isModalPresented) { ImageModalView(isPresented: $isModalPresented) } } } struct ImageModalView: View { @Binding var isPresented: Bool var body: some View { ScrollView { VStack(spacing: 14) { // 主体图片区域,替换为自己的图片资源名即可 Image("your_image_resource") .resizable() .scaledToFit() .cornerRadius(12) .padding(.top, 8) // 文本说明区域 Text("提示标题") .font(.headline) .fontWeight(.semibold) Text("这里是模态面板的说明文本,内容最多不超过3行,避免用户需要滚动过多内容才能看到操作按钮。") .font(.footnote) .multilineTextAlignment(.center) .foregroundColor(.secondary) // 操作按钮区域 Button { // 插入确认操作逻辑 isPresented = false } label: { Text("确认") .foregroundColor(.green) } Button(role: .cancel) { isPresented = false } label: { Text("取消") } } .padding(.horizontal, 16) .padding(.bottom, 8) } .navigationBarTitleDisplayMode(.inline) } } #Preview { MainView() }
符合watchOS HIG规范的设计说明
- 交互逻辑:使用系统原生
sheet修饰符实现模态弹出,默认支持左滑、数码表冠点击关闭操作,符合用户通用操作习惯 - 布局结构:核心图片放在最顶部优先展示,说明文本居中,操作按钮放在底部适配手表单手点击区域
- 视觉规范:图片添加系统通用圆角,文本层级清晰,取消按钮使用系统自带
cancel角色自动适配系统样式,背景使用默认半透明模糊效果和底层视图形成层级区分
注意事项
- 如果需要用户必须完成操作才能返回,可将
sheet替换为fullScreenCover实现全屏模态 - 主体图片最大宽度不要超过屏幕宽度的90%,避免内容溢出
- 操作按钮最多不超过3个,降低用户选择成本
内容的提问来源于stack exchange,提问作者mamutido
相关产品推荐
相关产品推荐

