如何在 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")
}
}
}
我有以下代码,我想将一些图像放在以红色突出显示的区域。我如何在 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")
}
}
}