简体   繁体   English

如何禁用UISlider Swift

[英]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. 我有一个UISlider但是我想在IF语句为true时禁用滑块功能。

I current have a UISlider with an If statement but can't workout how to disable it. 我目前有一个带有If语句的UISlider,但是无法锻炼如何禁用它。

    @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? 还是会在viewDidLoad中? If so how? 如果可以,怎么办?

All help is appreciated 感谢所有帮助

Set the enabled property to false. 将enabled属性设置为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. 如果要在视图控制器的其他功能中启用/禁用滑块,则需要为滑块创建IBOutlet属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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