我在应用程序中有自定义字体,我在 a 上使用它Text,如下所示:
struct CustomButton: View {
var label: String
var action: () -> Void
init(_ label: String, action: @escaping () -> Void) {
self.label = label
self.action = action
}
var body: some View {
Button(action: action) {
Text(label)
.padding()
}
}
}
Run Code Online (Sandbox Code Playgroud)
预览是:
struct CustomButton_Previews: PreviewProvider {
static var previews: some View {
VStack {
CustomButton("Simple g Button") {
}
.font(.custom("NexaBold", size: 40))
.foregroundColor(.red)
}
.background(Color.black)
.previewDevice(PreviewDevice(rawValue: "iPhone 8"))
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,角色g没有很好地显示出来,从底部剪下来。我已经在字体文件中验证它是完整的,但Text显示它是从底部剪下来的。
我试图添加更多,padding但这并不能解决问题。
请帮忙,我该如何解决?
好吧,下面看起来像解决方法,但它有效,所以尝试......

Button(action: action) {
Text(label)
.baselineOffset(2) // << shifted baseline !
.font(.custom("Nexa Bold", size: 40))
.padding()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |