Skip to content

Instantly share code, notes, and snippets.

@arashkashi
Created June 11, 2021 06:57
Show Gist options
  • Save arashkashi/d325db0a925a099da6dc95de533e2acf to your computer and use it in GitHub Desktop.
Save arashkashi/d325db0a925a099da6dc95de533e2acf to your computer and use it in GitHub Desktop.
experiment how start and end point affect gradient
//
// ContentView.swift
// testswiftUI
//
// Created by Arash on 2021-06-10.
//
import SwiftUI
struct ContentView: View {
@State private var startx: Double = 0
@State private var starty: Double = 0
@State private var endx: Double = 0
@State private var endy: Double = 0
var body: some View {
VStack {
Rectangle().fill(LinearGradient(gradient: Gradient(colors: [Color.black, Color.white]),
startPoint: UnitPoint(x: CGFloat(startx), y: CGFloat(starty)),
endPoint: UnitPoint(x: CGFloat(endx), y: CGFloat(endy))))
.frame(width: 200, height: 200)
Slider(value: $startx, in: 0...1)
Text("Start x: \(startx, specifier: "%.01f")")
Slider(value: $starty, in: 0...1)
Text("Start y: \(starty, specifier: "%.01f")")
Slider(value: $endx, in: 0...1)
Text("End x: \(endx, specifier: "%.01f")")
Slider(value: $endy, in: 0...1)
Text("End y: \(endy, specifier: "%.01f")")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment