2017-07-02 47 views
0

我想要做的是:變化UIButton的標題它被隱藏後

當用戶點擊「忘記密碼」的標籤: 1 UIButton的標題更改爲「發送」

2-密碼文本框是隱藏

3 - 取消標籤不是隱藏

,並且當用戶點擊取消: 1-密碼文本字段顯示

2- UIButton的標題是 「登錄」

3-舞蹈隱藏

@IBAction func forgotTapped(_ sender: UITapGestureRecognizer) { 

    if passwordtxt.isHidden == false { 
     loginbtn.titleLabel?.text = "send" 

    passwordtxt.isHidden = true 
     forgotLab.isHidden = true 
     top.constant = -50 

     cancelLb.isHidden = false 
    } else { 
     if passwordtxt.isHidden == true { 
     forgotLab.isHidden = false 

     if passwordtxt.isHidden == true { 

      passwordtxt.isHidden = false 
       loginbtn.titleLabel?.text = "login" 
      cancelLb.isHidden = true 
     } 
    } 

    } 

} 

@IBAction func cancelTapped(_ sender: Any) { 

    cancelLb.isHidden = true 
    forgotLab.isHidden = false 
    loginbtn.titleLabel?.text = "send" 

    if passwordtxt.isHidden == true { 

     passwordtxt.isHidden = false 

     top.constant = 50 


} 
} 

問題:

現在一切都很正常,但是當我點擊該按鈕時它是「發送」它變成「登錄」!它回到它的默認標題在黑色

有無論如何使UIButton保持「發送」,即使點擊它後?

UPDATE

if passwordtxt.isHidden == false { 
     loginbtn.setTitle("send", for: .normal) 

    passwordtxt.isHidden = true 
     forgotLab.isHidden = true 
     top.constant = -50 

     cancelLb.isHidden = false 
    } else { 
     if passwordtxt.isHidden == true { 
     forgotLab.isHidden = false 

     if passwordtxt.isHidden == true { 

      passwordtxt.isHidden = false 
      loginbtn.setTitle("login", for: .normal) 
      cancelLb.isHidden = true 
     } 
    } 

    } 

} 

@IBAction func cancelTapped(_ sender: Any) { 

    cancelLb.isHidden = true 
    forgotLab.isHidden = false 
    loginbtn.setTitle("send", for: .normal) 

    if passwordtxt.isHidden == true { 

     passwordtxt.isHidden = false 

     top.constant = 50 
} 
} 
+0

有,但首先,* *正是你希望看到的 「發送」 的UIButton被竊聽時什麼? (這樣做的「強力」方法是讓'forgotteped(sender:)'中的邏輯檢查標籤中的內容並進行相應處理,但可能會有更優雅的方式。) – dfd

+0

更改標題時,請使用函數'setTitle'而不是從titleLabel中改變它。 – TawaNicolas

+0

我想成爲「發送」 – leo0019

回答

0
@IBAction func forgotTapped(_ sender: UITapGestureRecognizer) { 

    if passwordtxt.isHidden == false { 

    passwordtxt.isHidden = true 
     loginbtn.setTitle("send", for: .normal) 

     forgotLab.isHidden = true 
     top.constant = -50 

     cancelLb.isHidden = false 
    } else { 
     if passwordtxt.isHidden == true { 

     forgotLab.isHidden = false 

     if passwordtxt.isHidden == true { 

      passwordtxt.isHidden = false 
      cancelLb.isHidden = true 
     } 
    } 

    } 

} 

@IBAction func cancelTapped(_ sender: Any) { 
    loginbtn.setTitle("login", for: .normal) 

    cancelLb.isHidden = true 
    forgotLab.isHidden = false 

    if passwordtxt.isHidden == true { 

     passwordtxt.isHidden = false 

     top.constant = 50 


} 
}