我有两段文本的水平堆栈(第二段以蓝色突出显示)。它非常适合 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)
}
}
Here is how it displays on a smaller device:
And how it shows on a larger device:
![large device display](https://i.stack.imgur.com/nSCDR.png)
struct ContentView: View {
var normalText: String = "Hello and Welcome to Stack "
var highlightedText: String = "Overflow"
var body: some View {
HStack() {
Group {
Text(normalText).bold() +
Text(highlightedText).bold()
.foregroundColor(.blue)
}
.lineLimit(1).font(.largeTitle)
Spacer()
}
.minimumScaleFactor(0.5)
}
}
+
被定义为 2 个文本,但不是 2 个视图,并且为lineLimit()
返回需要分组的连接文本的视图。我将组合的绳子加长以迫使其收缩。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)