Текст не переносится в быстром пользовательском интерфейсе - PullRequest
5 голосов
/ 08 июня 2019

Даже после установки .lineLimit (nil) текст не переносится.

var body: some View {
    VStack(alignment: .center) {
        Text("SwiftUI is a modern way to declare user interfaces for any Apple platform. ")
            .font(.title)
            .color(.red)
            .lineLimit(nil)
        Text("Create beautiful, dynamic apps faster than ever before.")
            .font(.system(size: 20))
            .lineLimit(nil)
    }.padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
}

enter image description here

Ответы [ 2 ]

3 голосов
/ 08 июня 2019

Попробуйте заменить второй текст lineLimit на число вместо nil:

VStack(alignment: .leading) {
  Text("SwiftUI is a modern way to declare user interfaces for any Apple platform. ")
    .font(.title)
    .color(.red)
    .lineLimit(nil)
  Text("Create beautiful, dynamic apps faster than ever before.")
    .font(.system(size: 20))
    .lineLimit(2)
 }.padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))

Результат:

enter image description here

2 голосов
/ 08 июня 2019

Похоже, что font содержит атрибуты переноса строк.

Если вы измените его на body, то оно будет правильно упаковано!

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...