extension
View
{
func
hideKeyboard
() {
UIApplication
.shared.sendAction(
#selector
(
UIResponder
.resignFirstResponder), to:
nil
, from:
nil
, for:
nil
)
#endif
复制代码
struct ContentView: View {
@State var username: String = ""
@State var password: String = ""
var body: some View {
VStack {
Text("fanfou.one")
.font(.largeTitle)
.bold()
.frame(maxWidth: .infinity, alignment: .leading)
.padding(EdgeInsets.init(top: 16, leading: 16, bottom: 10, trailing: 10))
.foregroundColor(.blue)
Spacer().frame(width: 100, height: 80)
VStack {
Text("账号")
.font(.callout)
.bold()
.frame(maxWidth: .infinity, alignment: .leading)
TextField("请输入饭否账号", text: $username)
.textFieldStyle(RoundedBorderTextFieldStyle())
Spacer()
.frame(width: 100, height: 16, alignment: .center)
Text("密码")
.font(.callout)
.bold()
.frame(maxWidth: .infinity, alignment: .leading)
SecureField("请输入密码", text: $password)
.textFieldStyle(RoundedBorderTextFieldStyle())
}.padding()
Spacer().frame(width: 100, height: 60)
Button(action: {
Text("登录")
.fontWeight(.bold)
.bold()
.foregroundColor(.white)
.frame(width: UIScreen.main.bounds.width - 32, height: 44, alignment: .center)
.background(Color.blue)
.cornerRadius(22)
Spacer()
.onTapGesture {
print("tap")
self.hideKeyboard()
swiftuione
developer