我有3個滑塊作爲顯示上述:編程變化滑塊值和更新標籤
而當「最小尖端」,它比「默認尖端」等於或大於,我加1「默認提示「。而且它也是默認到最大提示的邏輯。
所以,直到現在我有這個代碼,部分工作,因爲默認提示的滑塊增長在用戶界面中,但標籤不更新,因爲代理不被調用。
@IBOutlet weak var minLabel: UILabel!
@IBOutlet weak var defaultLabel: UILabel!
@IBOutlet weak var maxLabel: UILabel!
@IBOutlet weak var minSlider: UISlider!
@IBOutlet weak var defaultSlider: UISlider!
@IBOutlet weak var maxSlider: UISlider!
override func viewDidLoad() {
super.viewDidLoad()
minSlider.addTarget(self, action: #selector(SettingsViewController.minSliderValueChanged(_:)), forControlEvents: UIControlEvents.AllEvents)
defaultSlider.addTarget(self, action: #selector(SettingsViewController.defaultSliderValueChanged(_:)), forControlEvents: UIControlEvents.AllEvents)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func minSliderValueChanged(sender: UISlider) {
let valueMin = Int(minSlider.value)
let valueDefault = Int(defaultSlider.value)
_ = Int(maxSlider.value)
minLabel.text = "Min tip: \(valueMin)%"
if(valueMin >= valueDefault){
defaultSlider.value = Float(valueMin+1)
}
}
@IBAction func defaultSliderValueChanged(sender: UISlider) {
let value = Int(defaultSlider.value)
defaultLabel.text = "Default tip: \(value)%"
}
@IBAction func maxSliderValueChanged(sender: UISlider) {
let value = Int(maxSlider.value)
maxLabel.text = "Max tip: \(value)%"
}
我失蹤了什麼?
謝謝!這解決了問題的一部分 –