Text View在 SwiftUI 中,您可以使用trackingView 修饰符在 a 上设置字体跟踪(字母之间的间距) :
Text("Hello, World!")
.tracking(10)
如果您有 aButton并应用您的自定义ButtonStyle,则可以对按钮的样式进行各种修改,但由于configuration.label不是 but 的实例Text,ButtonStyleConfiguration.Label我无法直接访问 apply tracking。有没有办法做到这一点而不必直接在Button's上设置它label View?这似乎是你应该能够做的事情,因为它是与风格相关的事情,但我不知道如何完成它。
public struct MyStyle: ButtonStyle {
public func makeBody(configuration: Configuration) -> some View {
configuration.label
// (if I tried to put `.tracking` here it wouldn't work because it isn't Text)
.foregroundColor(Color.red)
.clipShape(Capsule())
// … etc.
}
}
ViewModifier 更改字体和跟踪外观〜相关但没有相关答案。
