🌀Gradient.linear()
╱🚧 under construction -> LinearGradient
swift⟩ custom ⟩ extension ⟩ Gradient ⟩ .linear()

// History:
// 2024.01.03
// - .right() -> .toTrailing()
// - .left() -> .toLeading()
// - .bottomLeft() -> .toBottomLeft()
// - ... etc.
import SwiftUI
extension Gradient {
// ------------- general linear gradient --------------
/// `Gradient.linear(from: start, to: end, colors: colors)`
///
/// - Parameters:
/// - from: 漸層開始的地方
/// - end: 漸層結束的地方
/// - colors: 漸層顏色 (`[Color]`)
public static func linear(
from start: UnitPoint,
to end: UnitPoint,
colors : [Color] // use array
) -> LinearGradient
{
LinearGradient(
gradient : Gradient(colors: colors),
startPoint: start,
endPoint : end
)
}
/// `Gradient.linear(from: start, to: end, colors: c1, c2, c3)`
///
/// - Parameters:
/// - from: 漸層開始的地方
/// - end: 漸層結束的地方
/// - colors: 漸層顏色 (`Color...`)
public static func linear(
from start: UnitPoint,
to end: UnitPoint,
colors : Color... // variadic parameter
) -> LinearGradient
{
linear(from: start, to: end, colors: colors)
}
// -------- specialized linear gradients -------
/// `Gradient.down(colors)`
/// - Parameters:
/// - colors: 漸層顏色 (`[Color]`)
public static func down(_ colors: [Color]) -> LinearGradient {
linear(from: .top, to: .bottom, colors: colors)
}
/// `Gradient.down(color1, color2, color3)`
public static func down(_ colors: Color...) -> LinearGradient {
down(colors)
}
/// `Gradient.up(colors)`
public static func up(_ colors: [Color]) -> LinearGradient {
linear(from: .bottom, to: .top, colors: colors)
}
/// `Gradient.up(color1, color2, color3)`
public static func up(_ colors: Color...) -> LinearGradient {
up(colors)
}
/// `Gradient.toTrailing(colors)`
/// - Parameters:
/// - colors: 漸層顏色 (`[Color]`)
public static func toTrailing(_ colors: [Color]) -> LinearGradient {
linear(from: .leading, to: .trailing, colors: colors)
}
/// `Gradient.toTrailing(c1, c2, c3)`
public static func toTrailing(_ colors: Color...) -> LinearGradient {
toTrailing(colors)
}
/// `Gradient.toLeading(colors)`
public static func toLeading(_ colors: [Color]) -> LinearGradient {
linear(from: .trailing, to: .leading, colors: colors)
}
/// `Gradient.toLeading(c1, c2, c3)`
public static func toLeading(_ colors: Color...) -> LinearGradient {
toLeading(colors)
}
/// `Gradient.toBottomRight(colors)`
/// - Parameters:
/// - colors: 漸層顏色
public static func toBottomRight(_ colors: [Color]) -> LinearGradient {
linear(from: .topLeading, to: .bottomTrailing, colors: colors)
}
/// Gradient.toBottomRight(color1, color2, color3)
public static func toBottomRight(_ colors: Color...) -> LinearGradient {
toBottomRight(colors)
}
/// `Gradient.toTopLeft(colors)`
public static func toTopLeft(_ colors: [Color]) -> LinearGradient {
linear(from: .bottomTrailing, to: .topLeading, colors: colors)
}
/// `Gradient.toTopLeft(color1, color2, color3)`
public static func toTopLeft(_ colors: Color...) -> LinearGradient {
toTopLeft(colors)
}
/// `Gradient.topRight(colors)`
/// - Parameters:
/// - colors: 漸層顏色
public static func toTopRight(_ colors: [Color]) -> LinearGradient {
linear(from: .bottomLeading, to: .topTrailing, colors: colors)
}
/// Gradient.toTopRight(color1, color2, color3)
public static func toTopRight(_ colors: Color...) -> LinearGradient {
toTopRight(colors)
}
/// Gradient.toBottomLeft(colors)
public static func toBottomLeft(_ colors: [Color]) -> LinearGradient {
linear(from: .topTrailing, to: .bottomLeading, colors: colors)
}
/// Gradient.toBottomLeft(color1, color2, color3)
public static func toBottomLeft(_ colors: Color...) -> LinearGradient {
toBottomLeft(colors)
}
}SwiftUI ⟩ Drawing and Animation ⟩ LinearGradient
ShapeStyle extension ShapeStyle+LinearGradient for LinearGradient.
History
(unknown)
2024.01.03
Last updated
Was this helpful?