Skip to content

Instantly share code, notes, and snippets.

@PetreVane
Created June 20, 2020 19:58
Show Gist options
  • Save PetreVane/0728ff0cc176c451f65db58e256c9f8a to your computer and use it in GitHub Desktop.
Save PetreVane/0728ff0cc176c451f65db58e256c9f8a to your computer and use it in GitHub Desktop.
How to add StarWars text like and heart that changes size and color when pressed
import SwiftUI
struct ContentView: View {
@State private var colorChange = false
@State private var sizeChange = false
var body: some View {
VStack(alignment: .center, spacing: 30) {
Text("Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma—which is living with the results of other people’s thinking. Don ’t let the noise of others’ opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition.")
.padding()
.font(.title)
.foregroundColor(Color.blue)
.multilineTextAlignment(.center)
.lineLimit(nil)
.truncationMode(.head)
.rotation3DEffect(.degrees(50), axis: (x: 1, y: 0, z: 0))
.shadow(color: .orange, radius: 2, x: 0, y: 20)
Image(systemName: "heart.fill")
.font(.system(size: 100))
.foregroundColor(colorChange ? .yellow : .red)
.scaleEffect(sizeChange ? 1.5 : 1)
.animation(.default)
.onTapGesture { self.colorChange.toggle() }
.onLongPressGesture { self.sizeChange.toggle() }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment