如何在 SwiftUI 中删除文本视图上方和下方的空间? [英] How to remove space above and below text view in SwiftUI?
本文介绍了如何在 SwiftUI 中删除文本视图上方和下方的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大小为 80 的文本.当我在此视图上放置边框时,我看到文本上方和下方都有额外的空间.为了在我的应用程序中节省空间,我需要删除这个空间.但我不知道是否可以正常使用?
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. To save space in my application, I need to remove this space. But I don't know if it's possible properly?
代码示例:
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)
}
}
结果:
我需要绿色结果:
推荐答案
垂直空间被 Text
本身占据.不建议添加固定的负填充.仅当文本和字体都被硬编码时才使用它.
The vertical space is occupied by the Text
itself. 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),
这篇关于如何在 SwiftUI 中删除文本视图上方和下方的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文