我有一个视图控制器,我右侧有一个名为" EDIT"的按钮,我想要做的是当用户点击编辑按钮然后按钮被隐藏并出现一个新按钮在名为" DONE"的那个按钮的位置。这是我到目前为止所做的代码 -
import UIKit
class ViewController: UIViewController {
@IBOutlet var editBtn: UIButton!
@IBOutlet var doneBtn: UIButton!
@IBOutlet var welcomeBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// action when user taps on welcome button
@IBAction func editBtnTapped(_ sender: Any) {
}
}
答案 0 :(得分:1)
只需更改您的代码 -
import UIKit
class ViewController: UIViewController {
@IBOutlet var editBtn: UIButton!
@IBOutlet var doneBtn: UIButton!
@IBOutlet var welcomeBtn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.doneBtn.isHidden = true
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// action when user taps on welcome button
@IBAction func editBtnTapped(_ sender: Any) {
self.editBtn.isHidden = true
self.doneBtn.isHidden = false
}
@IBAction func doneBtnTapped(_ sender: Any) {
self.doneBtn.isHidden = true
self.editBtn.isHidden = false
}
}