小编Lar*_*ars的帖子

SwiftUI: Animate Text color - foregroundColor()

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... …

ios swift swiftui

15
推荐指数
3
解决办法
7993
查看次数

SwiftUI:minimumScaleFactor 没有均匀地应用于堆栈元素

我有两个文本的水平堆栈(第二个以蓝色突出显示)。它非常适合 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)

以下是它在较小设备上的显示方式: 小设备显示 以及它如何在更大的设备上显示: 大型设备显示

ios swift swiftui

5
推荐指数
1
解决办法
633
查看次数

标签 统计

ios ×2

swift ×2

swiftui ×2