変数tipPercentage
、UISliderのアクションtipSliderAction
、およびUILabel tipPercentageLabel
と宣言しました。
また、clear
関数を作成しました。ボタンをタップすると、上記のすべてがデフォルト値にリセットされます。ここ
は、コードは次のとおりです。私はデフォルトに値をリセットする場所
スイスのuisliderの値と変数、ラベルの関連付け
var tipPercentage = 1
@IBOutlet weak var tipPercentageLabel: UILabel!
@IBOutlet weak var tipSlider: UISlider!
@IBAction func tipSliderAction(sender: UISlider) {
let currentValue = Int(sender.value)
tipPercentageLabel.text = ("\(currentValue)")
let percentage = Double(currentValue)/100
tipPercentage = percentage
}
@IBAction private func clear(sender: UIButton) {
tipSlider.value = 10
tipPercentageLabel.text = String(tipSlider.value)
tipPercentage = tipSlider.value
clear
関数です。私は私の質問は、個々の変数をリセットする代わりに、ちょうど1つをリセットする方法がある、そして他のすべてが自分自身を更新するだろうと思いますか?
例えば、を10に設定した場合、clear
関数では、clear
関数で設定しないと、tipPercentageLabel.text
とtipPercentage
が更新されます。
ありがとうございます。
ありがとうございます。 –