[英]How to remove space above and below text view in SwiftUI?
I have a text with a size of 80. When I put a border on this view, I see that there is additional space above and below the text.我有一个大小为 80 的文本。当我在这个视图上设置边框时,我看到文本上方和下方都有额外的空间。 To save space in my application, I need to remove this space.
为了在我的应用程序中节省空间,我需要删除这个空间。 But I don't know if it's possible properly?
但我不知道这是否可能正确?
Exemple of code:代码示例:
import SwiftUI
struct ContentView: View {
var body: some View {
Text("360°")
.font(Font.system(size: 80, weight: .thin, design: .default).monospacedDigit())
.border(Color.red, width: 2)
}
}
The result:结果:
I need the green result:我需要绿色结果:
The vertical space is occupied by the Text
itself.垂直空间被
Text
本身占据。 Adding fixed negative padding isn't recommended.不建议添加固定的负填充。 Use this, only if both text and font are hardcoded.
仅当文本和字体都被硬编码时才使用它。
Text("360°")
.font(Font.system(size: 80, weight: .thin, design: .default).monospacedDigit())
.padding(.vertical, -18)
.border(Color.red, width: 1),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.