-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathBasicAccessibilityDemo.swift
More file actions
104 lines (88 loc) · 3.49 KB
/
BasicAccessibilityDemo.swift
File metadata and controls
104 lines (88 loc) · 3.49 KB
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
103
104
import SwiftUI
import AccessibilitySnapshotPreviews
struct BasicAccessibilityDemo: View {
var body: some View {
VStack(alignment: .leading, spacing: 12) {
// MARK: - Label
DemoSection(title: "Label", description: "Text description for an element") {
Image(systemName: "star.fill")
.font(.title2)
.foregroundStyle(.yellow)
.accessibilityLabel("Favorite")
}
// MARK: - Value
DemoSection(title: "Value", description: "Current state or content") {
HStack {
Text("Progress")
Spacer()
Text("75%")
.foregroundStyle(.secondary)
}
.accessibilityElement(children: .combine)
.accessibilityValue("75 percent complete")
}
// MARK: - Hint
DemoSection(title: "Hint", description: "What happens when activated") {
Button("Delete") {}
.buttonStyle(.bordered)
.tint(.red)
.accessibilityHint("Removes this item permanently")
}
// MARK: - Traits
DemoSection(title: "Traits", description: "Element type and behavior") {
Text("Section Header")
.font(.headline)
.accessibilityAddTraits(.isHeader)
}
// MARK: - Input Labels
DemoSection(title: "Input Labels", description: "Voice Control phrases") {
Button {} label: {
Image(systemName: "mic.fill")
}
.buttonStyle(.bordered)
.accessibilityLabel("Microphone")
.accessibilityInputLabels(["Microphone", "Mic", "Record", "Voice"])
}
// MARK: - Activation Point
DemoSection(title: "Activation Point", description: "Custom tap target") {
RoundedRectangle(cornerRadius: 8)
.fill(Color.blue)
.frame(width: 60, height: 40)
.overlay(
Circle()
.fill(Color.white)
.frame(width: 8, height: 8)
.offset(x: 20, y: 10)
)
.accessibilityLabel("Custom tap target")
.accessibilityActivationPoint(CGPoint(x: 50, y: 30))
}
// MARK: - Element Grouping
DemoSection(title: "Element Grouping", description: "Combine children") {
HStack {
Image(systemName: "person.circle.fill")
.font(.title2)
VStack(alignment: .leading, spacing: 2) {
Text("John Doe")
.font(.subheadline)
.fontWeight(.medium)
Text("Online")
.font(.caption2)
.foregroundStyle(.green)
}
}
.padding(8)
.background(Color(.secondarySystemBackground))
.cornerRadius(8)
.accessibilityElement(children: .combine)
}
Spacer()
}
.padding()
.navigationTitle("Basic Accessibility")
}
}
#Preview {
BasicAccessibilityDemo()
.accessibilityPreview()
}