尝试将滑块中的变量乘以NSTimer变量。

时间:2015-06-21 18:25:03

标签: xcode swift

我制作了一个计时器,然后我添加了一个带有标签的滑块,该标签显示了它的值。我想要做的是让我的最后一个标签(Moneyadded)显示滑块值与NSt​​imer当前秒数的乘积。

import UIKit

class ViewController: UIViewController {

var timercount = 0
var timerRunning = false
var timer = NSTimer()
var myVaribale: Int = 0

override func viewDidLoad() {
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("update"), userInfo: nil, repeats: true)
}

func update() {
    // fired once a second
    myVaribale += 258
}



@IBOutlet weak var timerlabel: UILabel!

func counting(){

    timercount += 1
    timerlabel.text = "\(timercount)"
   var timerValue = timercount.value

}

@IBAction func Clockin(sender: UIButton) {
    if timerRunning == false{
        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("counting"), userInfo: nil, repeats: true)
        timerRunning = true
    }
}


@IBAction func Clockout(sender: UIButton) {
    if timerRunning == true{
        timer.invalidate()
        timerRunning = false
    }

}


@IBAction func Restart(sender: UIButton) {
    timercount = 0
    timerlabel.text = "0"
}



@IBOutlet weak var Slider: UISlider!


@IBOutlet weak var Label: UILabel!

@IBAction func valuechanged(sender: UISlider) {
var currentValue = Int(Slider.value)

    Label.text = "\(currentValue)"

}

@IBOutlet weak var Moneyadded: UILabel!
\\this is for the label (text) that I want the NStimer to be multiplied by the slider value.

1 个答案:

答案 0 :(得分:0)

counting功能更改为以下内容:

/** Gets triggered once every second */
func counting(){
    timercount += 1
    timerlabel.text = "\(timercount)"
    Moneyadded.text = "\(timercount * Int(Slider.value))"
}