-
Notifications
You must be signed in to change notification settings - Fork 5
/
ContentView.swift
103 lines (90 loc) · 2.77 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Created by Shaban on 25/05/2021.
// Copyright (c) 2021 sha. All rights reserved.
//
import SwiftUI
import ChipGroup
struct FirstExample: View {
var body: some View {
ScrollView {
VStack(spacing: 50) {
Spacer().frame(height: 100)
ChipGroup1()
ChipGroup2()
ChipGroup3()
}
}
}
private func ChipGroup1() -> some View {
Group {
let items = [
ChipItem(name: "Red"),
ChipItem(name: "Green"),
ChipItem(name: "Blue"),
ChipItem(name: "Purple"),
ChipItem(name: "Orange")
]
ChipGroup(
chips: items,
width: UIScreen.main.bounds.width - 120,
selection: .none,
selectedBackground: Capsule().fill(Color.orange),
deselectedBackground: Capsule().fill(Color.pink.opacity(0.8)),
selectedTextColor: .white,
deselectedTextColor: .white,
font: .system(size: 20, weight: .bold, design: .default)
)
}
}
private func ChipGroup2() -> some View {
Group {
let items = [
ChipItem(name: "1", isSelected: true),
ChipItem(name: "2"),
ChipItem(name: "3")
]
ChipGroup(
chips: items,
width: UIScreen.main.bounds.width - 120,
selection: .single,
selectedBackground: CircleBackground(color: .green),
deselectedBackground: CircleBackground(color: .yellow),
selectedTextColor: .white,
deselectedTextColor: .white,
font: .system(size: 20, weight: .bold, design: .default)
)
}
}
private func ChipGroup3() -> some View {
Group {
let items = [
ChipItem(name: "First"),
ChipItem(name: "Second"),
ChipItem(name: "Third")
]
ChipGroup(
chips: items,
width: UIScreen.main.bounds.width - 120,
selection: .multi,
font: .system(size: 20, weight: .bold, design: .default)
)
}
}
}
struct CircleBackground: View {
var color: Color
var body: some View {
content()
}
private func content() -> some View {
VStack(spacing: 6) {
Circle().fill(color)
.frame(width: 70, height: 70)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
FirstExample()
}
}