Skip to content

Commit 37c18cb

Browse files
authored
Merge pull request Jinxiansen#1 from alexp141/menus
Menus
2 parents 1963d56 + a44deb2 commit 37c18cb

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

Example/Example/ContentView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ struct ContentView : View {
108108
NavigationLink(destination: FormPage(firstName: "", lastName: "")) {
109109
PageRow(title: "Form",subTitle: "表单视图")
110110
}
111+
NavigationLink(destination: MenuPage()) {
112+
PageRow(title: "Menu",subTitle: "Menu Page")
113+
}
111114
}
112115
Section(header: Text("导航视图")) {
113116
NavigationLink(destination: NavigationViewPage()) {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
}

0 commit comments

Comments
 (0)