我正在尝试断开 TextField 和 Text 组件上的线条,这可能吗?
已经尝试过使用 frames 和 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")
}
}
最佳答案
您可以对 TextView 使用 .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)
}
}
关于swift - 如何在 Swift UI 的 TextField 和 Text 组件中放置多行(断行)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56949913/