繁体   English   中英

如何在 SwiftUI 表单上放置背景图像

[英]How to put background image on SwiftUI Form

我有以下代码,我想将一些图像放在以红色突出显示的区域。 我怎么能在 SwiftUI 中做到这一点?

这是突出显示的红色区域示例: https : //ibb.co/6X2zvyq

struct ContentView: View {
    var body: some View {
        NavigationView {
            Form {
                Section(header: Text("Info")) {
                    HStack {
                        Text("Name")
                        Spacer()
                        Text("someName")
                    }
                    HStack {
                        Text("Surname")
                        Spacer()
                        Text("someSurname")
                    }
                }
            }
            .navigationBarTitle("Profile")
        }
    }
}

这是完整的一个模块代码。 使用 Xcode 11.7 测试。 名为“植物”的图像位于 Assets.xcassets 中

演示

extension UINavigationController {
    override open func viewDidLoad() {
        super.viewDidLoad()

        let appearance = UINavigationBarAppearance()
        appearance.configureWithTransparentBackground()
        appearance.backgroundImage = UIImage(named: "plant")

        navigationBar.standardAppearance = appearance
        navigationBar.compactAppearance = appearance
        navigationBar.scrollEdgeAppearance = appearance
    }
}

struct ContentView: View {
    var body: some View {
        NavigationView {
            Form {
                Section(header: Text("Info")) {
                    HStack {
                        Text("Name")
                        Spacer()
                        Text("someName")
                    }
                    HStack {
                        Text("Surname")
                        Spacer()
                        Text("someSurname")
                    }
                }
            }
            .navigationBarTitle("Profile")
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM