Code to set underline,I want to make the space between the text and the underline larger.
Text("underline text")
.underline()
How about use a custom view instead of.underline?
struct MyUnderline: View {
let color: Color = .black
let height: CGFloat = 1
var body: some View {
Rectangle()
.fill(color)
.frame(height: height)
}
}
Text("underline text")
MyUnderline()
.padding(.top, -10)
You could create a custom view that takes the text and underline padding as parameters
struct UnderlinedText: View {
var text: String
var underlinePadding: CGFloat
var body: some View {
VStack (spacing: underlinePadding) {
Text(text)
GeometryReader { proxy in
Rectangle()
.frame(width: proxy.size.width, height: 1)
}
}
}
}
And use it as follows
UnderlinedText(text: "Hello underlined text", underlinePadding: 10.0)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.