我正在尝试断开TextField和Text组件的行,这可能吗?
已经尝试使用框架和VStack,但是没有用
我正在使用的文本,我想第一个打破:
VStack (alignment: .leading){
Text(message.message)
.bold()
.foregroundColor(Color.black)
Text(self.dateString)
.font(.caption)
.foregroundColor(Color.gray)
}
我正在使用的TextField:
HStack {
TextField(self.$messageModel.message, placeholder: Text("Write a message..."),
onEditingChanged: { if $0 { self.kGuardian.showField = 0 }
})
.background(GeometryGetter(rect: $kGuardian.rects[0]))
Button(action: {
self.messageModel.to = self.user.uid
self.messageModel.status = "read"
self.messageModel.date = Date().timeIntervalSince1970
ChatService.sendMessage(message: self.messageModel)
self.messageModel.message = ""
}) {
Text("Send")
}
}
答案 0 :(得分:2)
您可以在文本视图中使用.lineLimit(nil)
。它支持多行文本并根据需要分配空间。
struct StackOverFlow : View {
var body: some View {
Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")
.lineLimit(nil)
}
}
答案 1 :(得分:0)
尝试将.padding()
放在VStack的按钮上。