如何设置容器的背景颜色? 我在Swift进行编码时的Begginer实际上是在本周开始的。请,我正在寻找有关将容器从灰色更改为黑色的帮助。无论如何,我都无法弄清楚如何将其更改为任何

问题描述 投票:0回答:2

我尝试使用光标,但失败了。
	

弥补您已将AppearanceMy canvas设置为Dark

, 使用

.listRowBackground(Color.clear)

尝试这种方法,如图所示 在示例代码中:
ios swift swiftui
2个回答
0
投票
struct ContentView: View { @State private var showingAlertSetup = false var body : some View { alertsView } @ViewBuilder // <--- here private var alertsView: some View { NavigationStack { // <--- here Form { HStack(spacing: 20) { Button(action: { showingAlertSetup = true }) { HStack { Image(systemName: "plus") Text("Add New Alert") } .padding() .foregroundColor(.blue) } Spacer() Button(action: { // Action for adding a recurring alert }) { HStack { Image(systemName: "plus") Text("Add Recurring Alert") } .padding() .foregroundColor(.blue) } } .padding(.vertical, 8) .listRowBackground(Color.clear) // <--- here Section(header: Text("Active Alerts")) { Text("alertSettings") // <--- for my testing // ForEach(alertSettings) { alert in // alertRow(for: alert) // } // .onDelete(perform: deleteAlert) // .listRowSeparator(.hidden) } .listRowBackground(Color.clear) // <--- here } .listStyle(PlainListStyle()) .navigationTitle("Alerts") } } func deleteAlert(at offsets: IndexSet) { // offsets.forEach { alertSettings.remove(at: $0) } } }

注意,debe debe duals使用
NavigationView
代替。
    
您需要2个修饰符:

。listrowinsets(.init())

为:
NavigationStack


0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.