I've been trying to work on animating various parts of the UI, but it seems as though you can't animate a SwiftUI Text's foregroundColor? I want to switch the color of some text smoothly when a state changes. This works fine if I animate the background color of the Text's surrounding view, but foreground color does not work. Has anyone had any luck animating a change like this? Unsure if this is an Xcode beta bug or it's intended functionality... …
我有两个文本的水平堆栈(第二个以蓝色突出显示)。它非常适合 iPhone XR,但在较小的设备(如 iPhone X)上时,文本不适合。我试图通过使用 minimumScaleFactor 来缩放文本来解决这个问题。然而,SwiftUI 似乎决定在堆栈中扩展什么。在此示例中,在较小的设备上,它会删除粗体并仅缩小第一个(非蓝色)元素。蓝色元素保持不变。关于为什么会发生这种情况的任何想法?如何一起缩小粗体文本元素的大小?谢谢!
var normalText: String
var highlightedText: String
var body: some View {
HStack() {
Text(normalText)
.font(.largeTitle)
.bold()
.lineLimit(1)
Text(highlightedText)
.font(.largeTitle)
.bold()
.lineLimit(1)
.foregroundColor(.blue)
Spacer()
}
.minimumScaleFactor(0.5)
}
}
Run Code Online (Sandbox Code Playgroud)