【问题标题】:List separators' weird lines before the text在文本之前列出分隔符的奇怪行
【发布时间】:2020-11-15 18:47:44
【问题描述】:

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

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.

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

【问题讨论】:

  • 哇,出了点问题! [![在此处输入图像描述][1]][1] 不属于此处。我试图在我的问题中添加图片。如何更新问题?
  • Xcode 12 / iOS 14 没有这种效果
  • 11.6 不是最新的吗?

标签: uitableview swiftui list-separator


【解决方案1】:

SwiftUI 2.0

无需更改 - 按原样工作

SwiftUI 1.0+

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

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

【讨论】:

  • 非常感谢,Asperi!有效。至于你之前对 Xcode 12 的评论。我试图在 AppStore 上更新它,它告诉我我有最新的(11.6)。我在这里想念什么?还是我应该购买新的 MacBook 来获得 Xcode 12?
  • 不,你不需要新的 MacBook :D...它是测试版,如果你愿意,你可以从 developer.apple.com 下载它(那里有免费帐户就足够了)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-30
  • 1970-01-01
  • 2018-06-14
  • 2021-04-26
  • 2017-06-27
  • 2016-08-21
相关资源
最近更新 更多