SwiftUI 1行で使えるグラデーション

Howto

コード例

import SwiftUI

struct ContentView: View {
    var body: some View {
        ZStack {
            AngularGradient(colors: [.red, .yellow, .green, .blue, .purple, .red], center: .bottomLeading)
        }
        .ignoresSafeArea()
    }
        
}

#Preview {
    ContentView()
}

AngularGradient

AngularGradient(colors: [.red, .yellow, .green, .blue, .purple, .red], center: .bottomLeading)

左から「center: .bottomLeading」「center: bottom」「center: bottomTrailing」

RadialGradient

 RadialGradient(colors: [.blue, .black], center: .center, startRadius: 20, endRadius: 200)

LinearGradient

 LinearGradient(stops: [
                .init(color: .red, location: 0.01),
                .init(color: .brown, location: 0.55)], startPoint: .top, endPoint: .bottom)

コメント

タイトルとURLをコピーしました