簡體   English   中英

重新排序時 SwiftUI 列表項上的黑色背景色

[英]Black background color on SwiftUI list item when reordering

我正在嘗試實現列表重新排序,基本代碼示例:

import SwiftUI

struct ContentView: View {

    @State var items = [
        "One",
        "Two",
        "Three"
    ]

    var body: some View {
        NavigationStack {
            ZStack {
                Color.gray
                    .ignoresSafeArea()

                List($items, id: \.self, editActions: .move) { $item in
                    ListItem(text: item)
                }
                .scrollContentBackground(.hidden)
                .listStyle(.plain)
            }
            .navigationTitle("Test")
            .navigationBarTitleDisplayMode(.inline)
        }
    }

}

struct ListItem: View {

    let text: String

    var body: some View {
        Text(text)
            .frame(maxWidth: .infinity)
            .foregroundColor(.white)
            .padding()
            .background(.blue)
            .clipShape(RoundedRectangle(cornerRadius: 4.0))
            .listRowSeparator(.hidden)
            .listRowBackground(Color.clear)
    }

}



struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

一切正常,但是當我長按開始拖動手勢時,列表項的背景顯示為黑色。 我已經添加了所有修飾符,例如listRowBackgroundscrollContentBackground ,但問題仍然存在。 知道我在這里做錯了什么嗎?

在此處輸入圖像描述

使用您的頁面背景顏色(灰色)作為您的listRowBackground修飾符。

    Text(text)
        .frame(maxWidth: .infinity)
        .foregroundColor(.white)
        .padding()
        .background(.blue)
        .clipShape(RoundedRectangle(cornerRadius: 4.0))
        .listRowSeparator(.hidden)
        .listRowBackground(Color.gray)

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM