Skip to content

Commit e72b79a

Browse files
committed
changed project iOS version to 16.2 and added an example Menu implementation
1 parent 1963d56 commit e72b79a

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

Example/Example/ContentView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct ContentView : View {
5252
}
5353
NavigationLink(destination: NavigationButtonPage()) {
5454
PageRow(title: "NavigationButton",subTitle: "按下时触发导航跳转的按钮")
55+
PageRow(title: "NavigationButton",subTitle: "按下时触发导航跳转的按钮")
5556
}
5657
NavigationLink(destination: Text("I'm Text")) {
5758
PageRow(title: "PresentationButton",subTitle: "触发时显示内容的按钮控件")
@@ -108,6 +109,9 @@ struct ContentView : View {
108109
NavigationLink(destination: FormPage(firstName: "", lastName: "")) {
109110
PageRow(title: "Form",subTitle: "表单视图")
110111
}
112+
NavigationLink(destination: MenuPage()) {
113+
PageRow(title: "Menu",subTitle: "Menu Page")
114+
}
111115
}
112116
Section(header: Text("导航视图")) {
113117
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)