我在应用程序中有自定义字体,我正在使用它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()
}
}
}
预览是:
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"))
}
}
正如你所看到的角色g
显示效果不好,从底部切开。我已经在字体文件中验证它是完整的,但是Text
将其显示为从底部切割。
我尝试添加更多padding
但这并不能解决问题。
请帮忙,我该如何修复它?
好吧,下面看起来像是解决方法,但它确实有效,所以尝试......
Button(action: action) {
Text(label)
.baselineOffset(2) // << shifted baseline !
.font(.custom("Nexa Bold", size: 40))
.padding()
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)