mcpField
L
liquid-glass

liquid-glass

github.com/casper-studios设计与 UI15322 次安装8 周前更新
代码仓库

关于 liquid-glass

面向原生 macOS 和 iOS 应用的设计技能,依据 Apple Liquid Glass 设计与人机界面指南提供规则和 SwiftUI 示例,涵盖材质、布局、排版、动效与无障碍设计。

主要功能

  1. 01玻璃层与内容层规则
  2. 02Liquid Glass 与材质示例
  3. 03SwiftUI 卡片、行和徽章
  4. 04间距、排版与形状指南
  5. 05无障碍适配与触控目标

适用场景

  1. 01设计浮于应用内容上方的导航和控件
  2. 02构建风格一致的卡片、行与状态徽章
  3. 03检查触控目标和 Dynamic Type 支持

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/casper-studios/casper-marketplace --skill liquid-glass

安装后在 Claude Code 中输入/liquid-glass确认已加载。

附带文件references/apple-hig.mdreferences/components.md

详细介绍

Liquid Glass 设计

使用 Apple 的 Liquid Glass 设计和 HIG 构建原生 macOS/iOS 应用。

核心规则

三层模型
┌─────────────────────────────────────────┐
│     GLASS LAYER (Navigation/Controls)   │  ← Glass here ONLY
├─────────────────────────────────────────┤
│         CONTENT LAYER (Your App)        │  ← Never glass here
└─────────────────────────────────────────┘

玻璃效果仅用于悬浮于内容上方的导航。绝不要用于内容本身。

五项原则
  1. 内容优先 - 玻璃悬浮于上方,让内容透显出来
  2. 以光线营造层次 - 通过折射营造层次,而非依赖不透明度
  3. 自适应着色 - 颜色会根据背景动态变化
  4. 语义强调 - 仅为主要操作添加着色
  5. 内置无障碍功能 - 系统会自动处理适配

材质(macOS 14+ / Pre-iOS 26)

// Card with material
.padding(24)
.background(.regularMaterial, in: RoundedRectangle(cornerRadius: 16, style: .continuous))

// Material options (lightest → heaviest):
// .ultraThinMaterial, .thinMaterial, .regularMaterial (default), .thickMaterial, .ultraThickMaterial

Liquid Glass API(iOS 26+ / macOS Tahoe)

// Basic
Button("Action") { }.glassEffect()

// Variants
.glassEffect(.regular)   // Standard UI
.glassEffect(.clear)     // Media backgrounds only
.glassEffect(.identity)  // Disabled

// Interactive (adds bounce/shimmer)
Button("Tap") { }.glassEffect(.regular.interactive())

// Multiple glass elements - MUST wrap in container
GlassEffectContainer(spacing: 30) {
    HStack {
        Button("A") { }.glassEffect()
        Button("B") { }.glassEffect()
    }
}

// Button styles
Button("Cancel") { }.buttonStyle(.glass)           // Secondary
Button("Save") { }.buttonStyle(.glassProminent).tint(.blue)  // Primary

基本模式

卡片
VStack(alignment: .leading, spacing: 12) {
    HStack {
        ZStack {
            Circle().fill(color.opacity(0.15)).frame(width: 36, height: 36)
            Image(systemName: icon).foregroundStyle(color)
        }
        Spacer()
    }
    Text(value).font(.system(size: 28, weight: .bold, design: .rounded))
    Text(label).font(.caption).foregroundStyle(.secondary)
}
.padding(20)
.background(.regularMaterial, in: RoundedRectangle(cornerRadius: 16, style: .continuous))
带悬停效果的行
HStack { content }
.padding(16)
.background(isHovering ? Color.primary.opacity(0.04) : .clear)
.background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 12, style: .continuous))
.onHover { withAnimation(.easeInOut(duration: 0.15)) { isHovering = $0 } }
徽章
HStack(spacing: 8) {
    Circle().fill(isActive ? .green : .orange).frame(width: 8, height: 8)
    Text(status).font(.caption).fontWeight(.medium)
}
.padding(.horizontal, 12).padding(.vertical, 8)
.background(.regularMaterial, in: Capsule())
带着色背景的图标
ZStack {
    Circle().fill(color.opacity(0.15)).frame(width: 32, height: 32)
    Image(systemName: icon).font(.system(size: 14, weight: .semibold)).foregroundStyle(color)
}

形状

// Always use .continuous
RoundedRectangle(cornerRadius: 16, style: .continuous)  // Cards
RoundedRectangle(cornerRadius: 12, style: .continuous)  // Rows
RoundedRectangle(cornerRadius: 8, style: .continuous)   // Small elements
Capsule()  // Pills, badges
Circle()   // Icons

颜色

// Semantic foreground
.foregroundStyle(.primary)    // Main content
.foregroundStyle(.secondary)  // Subtitles
.foregroundStyle(.tertiary)   // Timestamps

// Backgrounds
.background(.quaternary)
.background(.quaternary.opacity(0.5))

// Accent meanings
Color.blue    // Primary actions, selection
Color.green   // Success, active
Color.orange  // Warning, loading
Color.red     // Destructive, error
Color.purple  // Premium, AI
Color.cyan    // Security

// Tinted backgrounds: always 15% opacity
.fill(color.opacity(0.15))

排版

.font(.largeTitle).fontWeight(.bold)      // Page titles
.font(.headline).fontWeight(.semibold)    // Section headers
.font(.subheadline).fontWeight(.medium)   // Row titles
.font(.body)                               // Content (17pt default)
.font(.caption)                            // Metadata
.font(.caption2)                           // Timestamps
.font(.system(size: 28, weight: .bold, design: .rounded))  // Stats

规则: 最小字号为 11pt。避免使用 Ultralight/Thin/Light 字重。使用系统字体以支持动态字体大小。

间距(8pt 网格)

// Standard values: 4, 8, 12, 16, 20, 24, 32, 40, 48

.padding(24)                    // Cards
.padding(16)                    // Rows
.padding(.horizontal, 12).padding(.vertical, 8)  // Badges

// Rule: external spacing ≥ internal spacing
VStack(spacing: 24) { CardView().padding(20) }  // Correct

SF Symbols

// Preferred: hierarchical for depth
Image(systemName: icon).symbolRenderingMode(.hierarchical).foregroundStyle(color)

// Match weight to nearby text
Image(systemName: "gear").font(.system(size: 14, weight: .semibold))

点击区域

// MINIMUM: 44pt × 44pt
Button { } label: { Image(systemName: "gear") }
    .frame(minWidth: 44, minHeight: 44)

动画

// Hover
.onHover { withAnimation(.easeInOut(duration: 0.15)) { isHovering = $0 } }

// Spring
withAnimation(.spring(response: 0.3)) { }
withAnimation(.bouncy) { }

// Entry
.opacity(appeared ? 1 : 0).offset(y: appeared ? 0 : 10)
.onAppear { withAnimation(.spring(response: 0.5, dampingFraction: 0.8)) { appeared = true } }

推荐做法与禁忌

推荐:

  • 卡片和工具栏使用 .regularMaterial
  • 所有圆角矩形均使用 .continuous
  • 图标背景使用 15% 不透明度
  • 将多个玻璃效果元素放入 GlassEffectContainer
  • 点击区域最小尺寸设为 44pt
  • 使用 8pt 网格间距
  • SF Symbols 使用 .hierarchical

禁忌:

  • 将玻璃效果用于内容(列表、表格)
  • 在没有容器的情况下叠加玻璃效果
  • 使用尖锐的圆角
  • 使用小于 11pt 的文本
  • 创建小于 44pt 的触控目标
  • 在玻璃效果上使用全彩图片

无障碍功能

系统会自动处理:

  • 降低透明度 → 玻璃效果更加不透明
  • 增强对比度 → 显示边框
  • 减少动态效果 → 不使用弹跳效果
  • 动态字体大小 → 文本缩放

如有需要,可手动覆盖:

@Environment(\.accessibilityReduceTransparency) var reduceTransparency
.glassEffect(reduceTransparency ? .identity : .regular)

参考资料

如需查看详细模式和示例,请参阅:

评论

支持 Markdown