How can I offset a Text such that exactly splits in the middle of the character. The problem that I face is that the character is not split nicely. What I have so far:
Text("8")
.font(.system(size: size, design: fontDesign))
.foregroundColor(fontColor)
.offset(x: 0, y: size/2)
.frame(width: size, height: size/2, alignment: .bottom)
.background(Color.black)
.clipShape(Rectangle())
Text("8")
.font(.system(size: size, design: fontDesign))
.foregroundColor(fontColor)
.offset(x: 0, y: -size/2)
.frame(width: size, height: size/2, alignment: .top)
.background(Color.black)
.clipShape(Rectangle())
This produces the following output:
I know that I can adjust the offset such that it aligns nicely (with size=50
, the y-offset would be 36
resp. -36
to align it). However, the size
must be variable. How can this be done?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…