Код: Выделить всё
struct AdaptiveText: View {
var text: String
let fontType: Font
let fontWeight: Font.Weight
var body: some View {
ViewThatFits{
//Shrinking Text
Text(text)
.lineLimit(1)
.minimumScaleFactor(0.7)
.fontWeight(fontWeight)
.font(fontType)
.multilineTextAlignment(.trailing)
//MultiLine Text
Text(text)
.lineLimit(nil)
.minimumScaleFactor(0.7)
.fontWeight(fontWeight)
.font(fontType)
.multilineTextAlignment(.trailing)
}
}
}
#Preview {
AdaptiveText(text: "Hi, this is quite a big sentence I guess", fontType: .title, fontWeight: .medium)
.border(.blue)
.background(.red)
.frame(maxWidth: .infinity, minHeight: 85)
.border(Color.red)
.padding()
.border(Color.red)
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... iple-lines
Мобильная версия