-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorPickerView.swift
37 lines (32 loc) · 1.2 KB
/
ColorPickerView.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
import SwiftUI
struct ColorPickerView: View {
@Binding var selectedColor: Color
private let colors: [Color] = [
.red, .yellow, .orange, .purple, .blue, .indigo, .green, .mint]
// 10 items in array
var body: some View {
VStack {
GeometryReader { geometry in
ScrollView(.horizontal) {
HStack(alignment: .center) {
ForEach(colors, id: \.self) {
color in
Circle()
.foregroundColor(color)
.frame(width: 30, height: 30)
.opacity(color == selectedColor ? 0.5 : 1.0)
.scaleEffect(color == selectedColor ? 1.1 : 1.0)
.onTapGesture {
selectedColor = color
}
}
}
.padding()
.background(.thinMaterial)
.cornerRadius(20)
.frame(width: geometry.size.width)
}
}
}
}
}