# color.gradient

[SwiftUI](/ios/swiftui.md) ⟩ [shapes](/ios/swiftui/shapes.md) ⟩ [ShapeStyle](/ios/swiftui/shapes/shapestyle.md) ⟩ [Color](/ios/swiftui/shapes/shapestyle/color.md) ⟩ <mark style="color:purple;">`.gradient`</mark>&#x20;

{% hint style="info" %}
color's standard gradient.
{% endhint %}

<figure><img src="/files/uPmsapF5qqjaey3ze4ik" alt=""><figcaption></figcaption></figure>

{% tabs %}
{% tab title="📘 手冊" %}

* SwiftUI ⟩ [Color](https://developer.apple.com/documentation/swiftui/color) ⟩ [.gradient](https://developer.apple.com/documentation/swiftui/color/gradient)：standard gradient for the color.
  {% endtab %}

{% tab title="👥 相關" %}

* [shadow](/ios/swiftui/view/drawing/shadow.md)
* [Gradient](/ios/swiftui/shapes/shapestyle/gradient.md)
  {% endtab %}

{% tab title="💾 程式" %}
{% tabs %}
{% tab title="StandardGradientView" %}

```swift
import SwiftUI

struct StandardGradientView: View {

    let spacing: CGFloat = 8
    let width: CGFloat = 80    // column width
    
    // 8 columns
    var columns: [GridItem] {
        // ⭐️ last GridItem's spacing is ignored.
        Array(
            repeating: GridItem(
                .fixed(width),        // ⭐️ fixed width
                spacing: spacing+6    // spacing to next column
            ), 
            count: 8
        )
    }
    
    var body: some View {
        // ⭐️ lazy v grid
        LazyVGrid(columns: columns, spacing: spacing) { // spacing between rows
            ForEach(Color.standardColors, id: \.self) { color in
                ColorSwatch(color: color, size: 80)
            }
        }.padding() 
    }
}

// previews
struct StandardGradientView_Previews: PreviewProvider {
    static var previews: some View {
        StandardGradientView()
    }
}
```

{% endtab %}

{% tab title="ColorSwatch" %}

```swift
import SwiftUI

struct ColorSwatch: View {
    
    let color: Color        
    let size: CGFloat    // swatch size
    
    var body: some View {
        VStack {
            
            Rectangle()
                .fill(color.gradient.shadow(.inner(
                    color: .bg2, radius: 2, x: 2, y: -2
                )))
                .frame(width: size, height: size)
                .border(Color.bg3)    // Color + system colors
            
            Text("\(color)")
                .font(.system(size: 14))
                .fixedSize()            // ⭐️ no wrap
        }
        .padding(4)
        .border(Color.bg3)
    }
}
```

{% endtab %}

{% tab title="⬆️ 需要" %}

* [system colors](/ios/custom/ext/color+/system.md)
  {% endtab %}
  {% endtabs %}
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/ios/swiftui/shapes/shapestyle/color/gradient.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
