1

我已经尝试了许多方法来使这里的白色背景清晰。似乎没有任何效果。

蓝色背景上的列表

struct OverlayChatView: View {
    var body: some View {
        ZStack {
            Color.clear
            List(0 ..< 5) { item in
                ChatMessageCell()
            }
            .listRowBackground(Color.clear)
            .background(Color.clear)
        }
    }
}

struct ChatMessageCell: View {
    var body: some View {
        HStack {
            Image(systemName: "person.crop.circle")
                .aspectRatio(1.0, contentMode: .fill)
            Text("This is a chat message of certain length to try to force a wrap in the preview.")
        }
    }
}

struct OverlayChatView_Previews: PreviewProvider {
    static var previews: some View {
        ZStack {
            Color.blue
                .ignoresSafeArea()
            OverlayChatView()
                .frame(maxWidth: 300.0, maxHeight: 300.0)
                .background(Color.clear)
        }
    }
}

很多人似乎都遇到了这个问题,有些人用非首发解决了这个问题:

.onAppear {
    UITableView.appearance().backgroundColor = UIColor.clear
    UITableViewCell.appearance().backgroundColor = UIColor.clear
}

我可以将单个列表项单元格设置为特定的不透明背景颜色。我什至无法将OverlayChatView或设置List为纯色,更不用说清除了。

iOS 14(模拟器,不是设备)

4

1 回答 1

0

包裹ForEach并设置背景颜色。

struct OverlayChatView: View {
    var body: some View {
        ZStack {
            Color.clear
            List {
                ForEach(0 ..< 5) {  item in //<-- Here
                    ChatMessageCell()
                }
                .listRowBackground(Color.blue) //<-- Here
            }
            .background(Color.clear)
        }
    }
}

或者你也可以使用colorMultiply

struct OverlayChatView: View {
    var body: some View {
        ZStack {
            Color.clear
            List(0 ..< 5) { item in
                    ChatMessageCell()
                
            }.colorMultiply(Color.blue) //<-- Here
            .background(Color.clear)
        }
    }
}
于 2021-05-13T05:33:30.523 回答