import SwifrUI
struct ContentView : View {
@State var userName : String =""
@State var passWord : String =""
var body: some View {
VStack {
Text("欢迎使用找不同")
.font(.title)
.padding()
Divider()
.background(Color(.brown))
Image(systemName:"person")
.resizeable()
.frame(width: 150, height: 150)
.cornerRadius(50)
VStack {
TextFied("请输入用户名", text: $userName)
.padding()
.padding(.leading,10)
.background(Color(.lightGray))
.cornerRadius(15)
TextFied("请输入密码", text: $passWord)
.padding()
.padding(.leading,10)
.background(Color(.lightGray))
.cornerRadius(15)
}
.padding()
Button(action: {
print("被点击了……")
}, label: {Text("登录")})
.padding()
Spacer()
}
}
}
struct ContentView_PreviewProvide {
static var previews: some View {
ContentView()
}
}
import SwifrUI
let lightGrayColor = Color(red: 239.0/255.0, green: 243.0/255.0, blue: 244.0/255.0, opacity: 1.0)
struct ContentView : View {
@State var userName : String = ""
@State var passWord : String = ""
@State private var alertFlag : Bool = false
@State private var alertMsg : String = ""
var body: some View {
VStack {
Text("欢迎使用找不同")
.font(.title)
.padding()
Divider()
.background(Color(.brown))
Image(systemName:"person")
.resizeable()
.frame(width: 150, height: 150)
.cornerRadius(50)
VStack {
TextFied("请输入用户名", text: $userName)
.padding()
.padding(.leading,10)
.background(Color(.lightGray))
.cornerRadius(15)
TextFied("请输入密码", text: $passWord)
.padding()
.padding(.leading,10)
.background(Color(.lightGray))
.cornerRadius(15)
}
.padding()
Button(action: {
if self.userName == "Zfchen" && self.passWord == "123" {
self.alertFlag = ture
self.alertMsg = "登录成功"
}
else {
self.alertFlag = ture
self.alertMsg = "登录失败"
}
}, label:{
Text("登录")
.font(.headline)
.foregroundColor(.white)
.frame(width: 220, height: 60)
.background(Color.green)
.cornerRadius(15.0)
})
.padding()
Spacer()
}
.alert(isPresented: $alertFlag) { () -> Alert in
Alert(title: Text("登录提醒"), message: Text(self.alertMsg), dismissButton: .default(Text("确定")))
}
}
}
struct ContentView_PreviewProvide: PreviewProvide {
static var previews: some View {
ContentView()
}
}