-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentView.swift
59 lines (45 loc) · 1.57 KB
/
ContentView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// ContentView.swift
// WhyNotTry
//
// Created by Andrzej Kapczyński on 04/04/2024.
//
import SwiftUI
struct ContentView: View {
var activities = ["Archery", "Baseball", "Basketball", "Bowling", "Boxing", "Cricket", "Curling", "Fencing", "Golf", "Hiking", "Lacrosse", "Rugby", "Squash"]
var colors: [Color] = [.blue, .cyan, .gray, .green, .indigo, .mint, .orange, .pink, .purple, .red]
@State private var selected = "Archery"
@State private var id = 1
var body: some View {
VStack {
Text("Why not try...").font(.largeTitle.bold())
.padding()
Spacer()
VStack {
Circle()
.fill(colors.randomElement() ?? .blue)
.padding()
.overlay(
Image(systemName: "figure.\(selected.lowercased())")
.font(.system(size: 144))
.foregroundColor(.white)
)
Text("\(selected)!").font(.title)
}
.id(id)
.transition(.slide)
Spacer()
Button("Try again") {
withAnimation(.easeInOut(duration: 0.3)) {
selected = activities.randomElement() ?? "Archery"
id += 1
}
}
.buttonStyle(.borderedProminent)
.padding()
}
}
}
#Preview {
ContentView()
}