forked from sindresorhus/Settings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountsView.swift
More file actions
78 lines (73 loc) · 2.16 KB
/
AccountsView.swift
File metadata and controls
78 lines (73 loc) · 2.16 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
import SwiftUI
import Preferences
/**
Function wrapping SwiftUI into `PreferencePane`, which is mimicking view controller's default construction syntax.
*/
let AccountsPreferenceViewController: () -> PreferencePane = {
/// Wrap your custom view into `Preferences.Pane`, while providing necessary toolbar info.
let paneView = Preferences.Pane(
identifier: .accounts,
title: "Accounts",
toolbarIcon: NSImage(systemSymbolName: "person.crop.circle", accessibilityDescription: "Accounts preferences")!
) {
AccountsView()
}
return Preferences.PaneHostingController(pane: paneView)
}
/**
The main view of “Accounts” preference pane.
*/
struct AccountsView: View {
@State private var isOn1 = true
@State private var isOn2 = false
@State private var isOn3 = true
@State private var selection1 = 1
@State private var selection2 = 0
@State private var selection3 = 0
private let contentWidth: Double = 450.0
var body: some View {
Preferences.Container(contentWidth: contentWidth) {
Preferences.Section(title: "Permissions:") {
Toggle("Allow user to administer this computer", isOn: $isOn1)
Text("Administrator has root access to this machine.")
.preferenceDescription()
Toggle("Allow user to access every file", isOn: $isOn2)
}
Preferences.Section(title: "Show scroll bars:") {
Picker("", selection: $selection1) {
Text("When scrolling").tag(0)
Text("Always").tag(1)
}
.labelsHidden()
.pickerStyle(RadioGroupPickerStyle())
}
Preferences.Section(label: {
Toggle("Some toggle", isOn: $isOn3)
}) {
Picker("", selection: $selection2) {
Text("Automatic").tag(0)
Text("Manual").tag(1)
}
.labelsHidden()
.frame(width: 120.0)
Text("Automatic mode can slow things down.")
.preferenceDescription()
}
Preferences.Section(title: "Preview mode:") {
Picker("", selection: $selection3) {
Text("Automatic").tag(0)
Text("Manual").tag(1)
}
.labelsHidden()
.frame(width: 120.0)
Text("Automatic mode can slow things down.")
.preferenceDescription()
}
}
}
}
struct AccountsView_Previews: PreviewProvider {
static var previews: some View {
AccountsView()
}
}