【发布时间】:2020-11-06 16:16:09
【问题描述】:
我有一个sheet,它显示了上传文件的进度。它看起来像这样:
如您所见,更改的行(“3.4 MB of 13.9...”)被截断。这是因为它以一个宽度开始,但随后可以随着字符串中的不同数字增长。
我尝试了以下方法,作为为尽可能大的字符串保留空间的技巧。它可以工作,但并不理想,因为白色的Rectangle 在黑暗模式下无法工作。
VStack(spacing: 0) {
Text("Uploading").bold()
Spacer().frame(height: 3)
Text("\(currentFilename)")
Text("\(completedFiles) of \(totalFiles) files")
ZStack {
Text("12345 KB of 12345 KB") // Biggest possible string
Rectangle().fill(Color.white) // But how to hide it ?
Text("\(bytes) of \(totalBytes)")
}
ProgressView(value: fraction)
Button("Cancel") { ... }
}.padding()
我没有看到 Color.systemBackgroundColor 或类似的替代 Color.white。
任何人都知道像这样为文本保留空间的好技巧吗?是我的ZStack 想法还是别的什么?
【问题讨论】:
标签: macos swiftui swiftui-text