繁体   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