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?
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. 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),