swiftui - SwiftUI:在 Text 之间添加仅 1 的填充会创建一个巨大的填充 - 如何实际制作一个小填充?
问题描述
我有Texts
inside VStack
,我想在其中添加一些空格。
但是,设置最小可能的填充 (= 1) 会创建一个太大的填充,而填充为零则根本不会创建任何填充。
似乎 SwiftUI 以某种方式计算realPadding = declaredPadding > 0 ? declaredPadding + 8 : 0
,这使得更小的填充无法实现。
为什么会这样?这种行为是否真的记录在某处?
现在看来,如果我想拥有例如。文本之间的2pt差距,我不走运。
有没有办法在文本视图之间实际获得比我得到的更小的填充.padding(.bottom, 1)
?
Nikita Tonsky批评了这种“自动”行为,但他没有想出解决方案。
要粘贴到游乐场的示例代码:
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
VStack {
VStack{
Text("Hello World")
.background(Color.red)
.padding(.bottom, 0)
Text("padding 0")
.background(Color.red)
}
.padding()
VStack{
Text("Hello World")
.background(Color.red)
.padding(.bottom, 1)
Text("padding 1 - a huge step-up from 0, why?")
.background(Color.red)
}
.padding()
VStack{
Text("Hello World")
.background(Color.red)
.padding(.bottom, 2)
Text("padding 2 - just 1 pt larger than 1")
.background(Color.red)
}
.padding()
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
它的外观:
解决方案
推荐阅读
- c# - 天气技能 Azure Web 测试自行运行,连接到虚拟助手时不起作用
- python - 如何通过仅在python中的列表中给出该元素的特定部分来查找列表中元素的索引
- python - 在 Python 中从 Active Directory 获取不记名令牌
- actionscript-3 - 第一个问题!NPC 步行循环随机发生器按预期工作(边界确实需要调整),但不播放嵌套的步行动画?(AS3)
- typescript - TypeScript 抱怨当它是对象时返回布尔值
- c# - ASP.Net Core MVC Ajax json 响应
- continuous-integration - 如何在已经展开的锚点下重用锚定条目?
- java - 如何将文件下载到java中的特定文件夹中?
- javascript - 如何在 React Native 中连接 url
- php - PHPUnit mock - 调用父 __get/__set/__isset