我已经为长按按钮创建了一个工作,但是如何设置长按按钮并将数字添加到标签,如 1+1+1+1+1
import UIKit
class ViewController: UIViewController {
var Step : Int = 0
var timer = NSTimer()
@IBOutlet weak var CounterLabel: UILabel!
@IBAction func longPressButton(sender: UILongPressGestureRecognizer) {
print("longPressFunc")
}
func addNumberToLabel(){
Step = Step + 1
updateLabel()
}
func updateLabel(){
//Step = Step + 1
CounterLabel.text = String(Step)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(ViewController.longPressFunc(_:)))
longPressRecognizer.allowableMovement = 10
//longPressRecognizer.minimumPressDuration = 1.0
self.view.addGestureRecognizer(longPressRecognizer)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func longPressFunc(sendor: UILongPressGestureRecognizer){
//timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(ViewController.addNumberToLabel), userInfo: nil, repeats: true)
updateLabel()
}
}