Skip to content

Menus #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Example/Example/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ struct ContentView : View {
NavigationLink(destination: FormPage(firstName: "", lastName: "")) {
PageRow(title: "Form",subTitle: "表单视图")
}
NavigationLink(destination: MenuPage()) {
PageRow(title: "Menu",subTitle: "Menu Page")
}
}
Section(header: Text("导航视图")) {
NavigationLink(destination: NavigationViewPage()) {
Expand Down
68 changes: 68 additions & 0 deletions Example/Example/Page/Container/MenuPage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// MenuPage.swift
// Menu Example
//
// Created by alexp141 on 4/28/23.
// Copyright © 2023 晋先森. All rights reserved.
//

import SwiftUI

//showing of Menus introduced in iOS 14
struct MenuPage: View {
@State private var message: String = "Click the menu button"
@State private var image: Image?
@State private var messageColor: Color = .black

var body: some View {
VStack {
Text(message).foregroundColor(messageColor)
if let image = image {
image.resizable().frame(width: 200, height: 200)
}
Menu {
Button("Display Text") {
self.message = "You have clicked the text button"
}

Button("Show Image") {
self.image = Image("icon")

}
//Menus can appear inside other Menus
Menu {
Button("Red") {
self.messageColor = .red
}
Button("Green") {
self.messageColor = .green
}
Button("Blue") {
self.messageColor = .blue
}
Button("Black") {
self.messageColor = .black
}
} label: {
Button("Text Color") {
//button clicked
}
}
} label: {
Button("Menu") {
//button clicked
}.frame(width: 150, height: 35)
.foregroundColor(.white)
.background(.blue)
.cornerRadius(10.0)
}
}

}
}

struct MenuPage_Previews: PreviewProvider {
static var previews: some View {
MenuPage()
}
}