HW-App畫面解鎖練習

1.主要應用的View,Label,Button,Image

使用四個image view 將其設定系統內建的star icon當作密碼輸入圖示.

未輸入密碼時圖示
輸入密碼時icon會變更圖示以表示輸入

將11個Button 納到View下

2.拉Outlet

3.撰寫相關func

//設定密碼為9527
var
passwd = "9527"
var entercode = ""//設定密碼輸入時icon變動func imageChange() {switch entercode.count{case 1:passwdImageViews[0].isHighlighted = truepasswdImageViews[1].isHighlighted = falsepasswdImageViews[2].isHighlighted = falsepasswdImageViews[3].isHighlighted = falsecase 2:passwdImageViews[0].isHighlighted = truepasswdImageViews[1].isHighlighted = truepasswdImageViews[2].isHighlighted = falsepasswdImageViews[3].isHighlighted = falsecase 3:passwdImageViews[0].isHighlighted = truepasswdImageViews[1].isHighlighted = truepasswdImageViews[2].isHighlighted = truepasswdImageViews[3].isHighlighted = falsecase 4:passwdImageViews[0].isHighlighted = truepasswdImageViews[1].isHighlighted = truepasswdImageViews[2].isHighlighted = truepasswdImageViews[3].isHighlighted = truecheckPasswd()default:passwdImageViews[0].isHighlighted = falsepasswdImageViews[1].isHighlighted = falsepasswdImageViews[2].isHighlighted = falsepasswdImageViews[3].isHighlighted = false}}
//輸入完密碼檢查是否正確
func checkPasswd() {
if entercode == passwd {let vc = UIAlertController(title: "Correct", message: "Welcome Back", preferredStyle: .alert)let action = UIAlertAction(title: "OK", style: .default) { (_) inself.reset()}vc.addAction(action)present(vc, animated: true,completion: nil)}else{let vc = UIAlertController(title: "Worng", message: "passwd error", preferredStyle: .alert)let action = UIAlertAction(title: "OK", style: .cancel, handler: nil)vc.addAction(action)present(vc ,animated: true, completion: reset)}}//重置密碼
func reset() {
passwdImageViews[0].isHighlighted = falsepasswdImageViews[1].isHighlighted = falsepasswdImageViews[2].isHighlighted = falsepasswdImageViews[3].isHighlighted = falseentercode = ""}

4.拉Action

--

--