我想移动到另一个视图使用一个按钮从一个表单,我试图使一个设置页面.下面的代码,我管理如何从一个表单打开一个URL,现在我想打开另一个页面,但我没有现在如何做到这一点.
struct FormRowLinkView: View {
var icon: String
var color: Color
var text: String
var link: String
var body: some View {
HStack{
ZStack{
RoundedRectangle(cornerRadius: 8, style: .continuous)
.fill(color)
Image(systemName: icon)
.imageScale(.large)
.foregroundColor(Color.white)
}
.frame(width: 36, height: 36, alignment: .center)
Text(text).foregroundColor(Color.gray)
Spacer()
Button(action: {
guard let url = URL(string: self.link), UIApplication.shared.canOpenURL(url as URL) else {
return
}
UIApplication.shared.open(url as URL)
}) {}
Image(systemName: "chevron.right")
.font(.system(size: 14, weight: .semibold, design: .rounded))
}
.accentColor(Color(.systemGray2))
}
}
struct FormRowLinkView_Previews: PreviewProvider {
static var previews: some View {
FormRowLinkView(icon: "globe", color: Color.pink, text: "Website", link: "")
.previewLayout(.fixed(width: 375, height: 60))
.padding()
}
}
字符串
这是如何设置视图看起来像,我试图编码一个按钮,这样用户就可以点击它移动到另一个页面,我尝试了这么多的代码,但没有运气
struct SettingsView: View {
// Properties
@Environment(\.presentationMode) var presentationMode
// Body
var body: some View {
NavigationView{
VStack(alignment: .center, spacing: 0) {
// Form
Form{
// Section 3
Section(header: Text("Follow Us On Social Media")){
FormRowLinkView(icon: "person", color: Color.blue, text: "Profile", link: "")
FormRowLinkView(icon: "link", color: Color.blue, text: "Twitter", link: "")
}
.padding(.vertical, 3)
// Section 4
Section(header: Text("About the application")){
FormRowStaticView(icon: "gear", firstText: "Application", secondText: "Todo")
FormRowStaticView(icon: "checkmark.seal", firstText: "Compatibility", secondText: "iPhone, iPad")
FormRowStaticView(icon: "keyboard", firstText: "Developer", secondText: "John / G")
FormRowStaticView(icon: "paintbrush", firstText: "Designer", secondText: "Robort")
FormRowStaticView(icon: "flag", firstText: "Version", secondText: "1.0.0")
}.padding(.vertical, 3)
} // End of form
.listStyle(GroupedListStyle())
.environment(\.horizontalSizeClass, .regular)
// Footer
Text("Copyright All rights reserved. \nSultan")
.multilineTextAlignment(.center)
.font(.footnote)
.padding(.top, 6)
.padding(.bottom, 8)
.foregroundColor(Color.secondary)
} // End of VStack
.navigationBarItems(trailing: Button(action: {
self.presentationMode.wrappedValue.dismiss()
}) {
Image(systemName: "xmark")
}
)
.navigationBarTitle("Settings", displayMode: .inline)
.background(Color("ColorBackground").edgesIgnoringSafeArea(.all))
} // End of Navigation View
}
}
型
3条答案
按热度按时间wgx48brx1#
你可以使用
NavigationView
,在里面你可以使用NavigationLink():字符串
我希望这能起作用!如果它不起作用或它的错误,只是评论。
wnvonmuf2#
如果你想显示一个新的屏幕,像这样在你的内容视图中添加一个@State变量。
字符串
然后添加一个按钮,看起来像这样。
型
lymnna713#
将
Form
Package 成NavigationView
,然后NavigationLink
在内部工作。字符串