我有一个文本,当其字符串的长度超出 View 范围时,我想用.minimumScaleFactor(0.1)
进行修改。但是,即使原始字体大小非常合适,缩放也会每次都适用。
我的观点是这样构成的:
VStack(alignment: .center, spacing: 0) {
HStack {
Image("medal \(place)").resizable()
.foregroundColor(color)
.frame(width: 40, height: 40)
Spacer()
Text(username)
.font(.bold(16))
.lineLimit(1)
.minimumScaleFactor(0.1)
.frame(alignment: .trailing)
.foregroundColor(Color("mediumTextColor"))
}
Spacer()
Text(score)
.font(.extraBold(60))
.foregroundColor(color)
.lineLimit(1)
.minimumScaleFactor(0.7)
Spacer()
}
.frame(height: 96)
.padding(10)
.cornerRadius(16)
.overlay(RoundedRectangle(cornerRadius: 16)
.stroke(color, lineWidth: 2))
最佳答案
上面答案的延续。
重要的是修饰符的应用顺序:
Text("This is a really long sentence.")
.minimumScaleFactor(0.5)
.font(.custom("OpenSans", size: 15))
.lineLimit(1)
.layoutPriority(1)
除非需要其他用途,否则不需要GeometryReader
关于text - SwiftUI-文本minimumScaleFactor不会仅在需要时缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58563567/