为什么整个表单在SwiftUI中充当按钮?
Form {
VStack {
Spacer()
HStack {
Text("해야 할 일 : ")
TextField("해야 할 일", text: $addList.name)
}
Divider()
HStack {
Text("추가 설명 : ")
TextField("추가 설명", text: $addList.explanation)
}
.padding(.vertical)
Divider()
Button("추가") {
toDoList.append(addList)
addList = ToDoModel(name: "", explanation: "")
isAdd = true
}
.padding(5)
.background(RoundedRectangle(cornerRadius: 5).stroke(Color.blue, lineWidth: 1))
.frame(maxWidth: .infinity, alignment: .trailing)
.alert(isPresented: $isAdd, content: { Alert(
title: Text("추가 완료"),
primaryButton: .default(Text("OK")),
secondaryButton: .cancel(Text("취소"), action: { self.presentationMode.wrappedValue.dismiss() })
)})
}
.padding()
}
1条答案
按热度按时间htzpubme1#
我认为这是因为它都在一个VStack中。你把这些都放在一个Form {}中?