This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SwiftUI Coordinate Spaces example | |
// Xcode 12.3 | |
// We show two colored rectangles on screen. When any of these rectangles is tapped | |
// we convert the tap location into VStack's coordinate space and show a circle at | |
// that location. | |
import SwiftUI | |
struct ContentView: View { | |
@State var locationOfTapInStackCoords: CGPoint? { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SwiftUI Gestures Tiny Example | |
// Xcode 12.3 | |
// This gist shows how to use multiple gestures on same object. | |
// We draw a rectangle on screen that can be | |
// 1. pinch zoomed | |
// 2. rotated | |
// 3. tapped (single tap) to change opacity | |
// 4. tapped (double tap) to change color | |
// 5. long press to scale up (+0.2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Xcode 12.3 | |
import SwiftUI | |
class ViewModel: ObservableObject { | |
@Published var itemsInUpperStack: [String] = ["Drag me down", "Some more text"] | |
@Published var itemsInLowerStack: [String] = ["Drag me up", "one two three"] | |
func move(item: String) { | |
if !itemsInLowerStack.contains(item) { | |
itemsInLowerStack.append(item) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Xcode 12.3 | |
import SwiftUI | |
struct ContentView: View { | |
@State private var arr = [1,2,3] | |
var body: some View { | |
ForEach(arr, content: { | |
number in | |
RoundedRectangle(cornerRadius: 10) | |
.foregroundColor(.red) |