简体   繁体   中英

How to disable UISlider Swift

I've seen answers about this but no actual code explaining how to, I'm new to swift so really confused on how to perform this simple task.

I have a UISlider However I want to disable the sliders funcation when an IF statement is true.

I current have a UISlider with an If statement but can't workout how to disable it.

    @IBAction func radiusSlider(sender: UISlider) {
    if location == false {
    //Disable Slider
    } else {
            radiusData.radiusValue = Double(sender.value)
            radiusLabel.text = "Radius: \(sender.value)km"
            NSNotificationCenter.defaultCenter().postNotificationName(radiusValue, object: self)
    }
}

Or would this be in within the viewDidLoad? If so how?

All help is appreciated

Set the enabled property to false.

@IBAction func radiusSlider(sender: UISlider) {
    if location == false {
        sender.enabled = false
    } else {
        radiusData.radiusValue = Double(sender.value)
        radiusLabel.text = "Radius: \(sender.value)km"
        NSNotificationCenter.defaultCenter().postNotificationName(radiusValue, object: self)
    }
}

If you want to enable/disable your slider in other functions of your view controller, you will need to make an IBOutlet property for your slider.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM