File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,9 @@ struct ContentView : View {
108
108
NavigationLink ( destination: FormPage ( firstName: " " , lastName: " " ) ) {
109
109
PageRow ( title: " Form " , subTitle: " 表单视图 " )
110
110
}
111
+ NavigationLink ( destination: MenuPage ( ) ) {
112
+ PageRow ( title: " Menu " , subTitle: " Menu Page " )
113
+ }
111
114
}
112
115
Section ( header: Text ( " 导航视图 " ) ) {
113
116
NavigationLink ( destination: NavigationViewPage ( ) ) {
Original file line number Diff line number Diff line change
1
+ //
2
+ // MenuPage.swift
3
+ // Menu Example
4
+ //
5
+ // Created by alexp141 on 4/28/23.
6
+ // Copyright © 2023 晋先森. All rights reserved.
7
+ //
8
+
9
+ import SwiftUI
10
+
11
+ //showing of Menus introduced in iOS 14
12
+ struct MenuPage : View {
13
+ @State private var message : String = " Click the menu button "
14
+ @State private var image : Image ?
15
+ @State private var messageColor : Color = . black
16
+
17
+ var body : some View {
18
+ VStack {
19
+ Text ( message) . foregroundColor ( messageColor)
20
+ if let image = image {
21
+ image. resizable ( ) . frame ( width: 200 , height: 200 )
22
+ }
23
+ Menu {
24
+ Button ( " Display Text " ) {
25
+ self . message = " You have clicked the text button "
26
+ }
27
+
28
+ Button ( " Show Image " ) {
29
+ self . image = Image ( " icon " )
30
+
31
+ }
32
+ //Menus can appear inside other Menus
33
+ Menu {
34
+ Button ( " Red " ) {
35
+ self . messageColor = . red
36
+ }
37
+ Button ( " Green " ) {
38
+ self . messageColor = . green
39
+ }
40
+ Button ( " Blue " ) {
41
+ self . messageColor = . blue
42
+ }
43
+ Button ( " Black " ) {
44
+ self . messageColor = . black
45
+ }
46
+ } label: {
47
+ Button ( " Text Color " ) {
48
+ //button clicked
49
+ }
50
+ }
51
+ } label: {
52
+ Button ( " Menu " ) {
53
+ //button clicked
54
+ } . frame ( width: 150 , height: 35 )
55
+ . foregroundColor ( . white)
56
+ . background ( . blue)
57
+ . cornerRadius ( 10.0 )
58
+ }
59
+ }
60
+
61
+ }
62
+ }
63
+
64
+ struct MenuPage_Previews : PreviewProvider {
65
+ static var previews : some View {
66
+ MenuPage ( )
67
+ }
68
+ }
You can’t perform that action at this time.
0 commit comments