首页 > 解决方案 > 在文本之前列出分隔符的奇怪行

问题描述

似乎无法弄清楚这件事。在我的列表中,我在文本之前有这些白色(暗模式下为黑色)线条,我无法摆脱它们。有人告诉我,这意味着我编码错误。但它是什么?这是我的代码:

import SwiftUI

struct ContentView: View {

init(){
    UITableView.appearance().backgroundColor = .clear
}

var body: some View {
    
    List {
        Text("List Item 1").listRowBackground(Color("customColor"))
        Text("List Item 2").listRowBackground(Color("customColor"))
        Text("List Item 3").listRowBackground(Color("customColor"))
        Text("List Item 4").listRowBackground(Color("customColor"))
        Text("List Item 5").listRowBackground(Color("customColor"))
    }.background(Color("customColor"))
    }
}

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

然后在 appDelegates (didFinishLaunchingWithOptions) 我把这个:

在此处输入图像描述

UITableView.appearance().separatorColor = .darkGray.

发现了几个关于列表背景颜色的主题,但在那些主题中似乎没有人关心这些烦人的线条。我该怎么做才能摆脱它们?

标签: uitableviewswiftuilist-separator

解决方案


SwiftUI 2.0

无需更改 - 按原样工作

SwiftUI 1.0+

这是一个修复(使用 Xcode 11.4 / iOS 13.4 测试)

UITableViewCell.appearance().backgroundColor = .clear    // << add this one !!
UITableView.appearance().backgroundColor = .clear

推荐阅读