-
-
Save sturdysturge/1a3ec6ddf1a3d2f12f12479ce33de1bc to your computer and use it in GitHub Desktop.
RevDoc Toolbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
public struct ToolbarView: View { | |
@State var data: [String] | |
init() { | |
var data = [String]() | |
for _ in 1...5 { | |
data.append(UUID().uuidString) | |
} | |
self._data = State<[String]>(initialValue: data) | |
} | |
public var body: some View { | |
NavigationView { | |
List(data, id: \.self) { uuid in | |
Text(uuid) | |
.lineLimit(1) | |
} | |
.navigationTitle("UUID Generator") | |
.toolbar { | |
ToolbarItem(placement: .primaryAction) { | |
Button("Add") { | |
data.append(UUID().uuidString) | |
} | |
.padding(5) | |
.background(Color.blue) | |
.foregroundColor(.white) | |
.cornerRadius(5) | |
} | |
ToolbarItem(placement: .navigationBarLeading) { | |
Button("Delete All") { data.removeAll() } | |
} | |
ToolbarItem(placement: .bottomBar) { | |
Button("Sort A > Z") { data.sort() } | |
} | |
ToolbarItem(placement: .bottomBar) { | |
Button("Sort A > Z") { data.sort(by: >) } | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment