返回 Skill 列表
extension
分类: 开发与工程无需 API Key

"liquid-glass"

iOS 26 液态玻璃材质:glassEffect 修饰符、放置规则、修饰符顺序、交互性限制。在应用玻璃效果、使用半透明材质或为 iOS 26 及以上版本设计工具栏/标签栏样式时使用。触发词:glassEffect, .glass, 材质, 半透明, 液态玻璃, iOS 26, 工具栏样式。

person作者: jakexiaohubgithub

Liquid Glass

iOS 26 introduces Liquid Glass as the primary surface material. Apply it to key UI surfaces.

WHERE TO APPLY .glassEffect():

  • List row backgrounds and card surfaces
  • Floating action buttons and toolbar items
  • Empty state containers (ContentUnavailableView wrappers)
  • Tab bars and bottom toolbars (custom ones)
  • Segmented controls and chip groups
  • Modal sheet headers

WHERE NOT TO APPLY:

  • Text editing surfaces (TextEditor, TextField containers) — keep opaque for readability
  • Full-screen backgrounds — use solid AppTheme.Colors.background
  • Every single element — use glass on 2-4 key surfaces per screen maximum
  • Deeply nested views — glass on parent is enough

MODIFIER ORDER (CRITICAL):

// CORRECT — glass AFTER layout modifiers
Text("Label")
    .font(AppTheme.Fonts.headline)
    .padding()
    .glassEffect(.regular, in: .rect(cornerRadius: 12))

// WRONG — glass before padding
Text("Label")
    .glassEffect()
    .padding()

INTERACTIVITY:

  • .glassEffect(.regular.interactive()) ONLY on tappable elements (Button, NavigationLink, tappable rows)
  • .glassEffect(.regular) on static/display-only surfaces
  • Never use .interactive() on labels, headers, or decorative elements

GROUPING:

  • Wrap adjacent glass elements in GlassEffectContainer
  • Match GlassEffectContainer(spacing:) to the actual layout spacing
GlassEffectContainer(spacing: 12) {
    HStack(spacing: 12) {
        ActionButton(icon: "pencil")
            .glassEffect(.regular.interactive(), in: .circle)
        ActionButton(icon: "trash")
            .glassEffect(.regular.interactive(), in: .circle)
    }
}

PROMINENCE:

  • .regular — default for most surfaces
  • .prominent — high-emphasis elements (selected states, primary actions)
  • Use .prominent sparingly — one per screen section maximum

TINTING:

  • Tint with accent color for branded surfaces: .glassEffect(.regular.tint(AppTheme.Colors.accent))
  • Keep tint subtle — use the color directly, not at full opacity

LIST ROWS WITH GLASS:

List(items) { item in
    ItemRow(item: item)
        .listRowBackground(
            Rectangle()
                .glassEffect(.regular.interactive(), in: .rect(cornerRadius: 10))
                .padding(.horizontal, 4)
        )
}
.scrollContentBackground(.hidden)

BUTTON STYLES:

  • Use .buttonStyle(.glass) for standard glass buttons
  • Use .buttonStyle(.glassProminent) for primary/emphasized actions
Button("Save") { save() }
    .buttonStyle(.glassProminent)