Milap Jhumkhawala Milap Jhumkhawala - 3 months ago 7
Swift Question

Updating value of EFCircularSlider to UILabel

I am using a library called EFCircularSlider. The library is an ObjC and i have successfully imported it in my project. The issue is however i am not able to update the slider value in a UILabel.

let sliderFrame = CGRectMake(100, 150, 200, 200)
let circularSlider = EFCircularSlider(frame: sliderFrame)

circularSlider.addTarget(self,
action:#selector(TemperatureConversion.valueChange(_:)),
forControlEvents:UIControlEvents.ValueChanged
)

self.view.addSubview(circularSlider)

func valueChange(sender: EFCircularSlider){
circularSlider.minimumValue = 0
circularSlider.maximumValue = 100
circularSlider.currentValue = 0


upperLabel.text = "\(circularSlider.currentValue)"

}


enter image description here

This is how it is done in ObjC. Where am i going wrong?

Answer

You need to add this line inside viewDidLoad method instead of valueChange method. So add this line in viewDidLoad and change your valueChange like this.

override func viewDidLoad() {
    super.viewDidLoad()
    let sliderFrame = CGRectMake(100, 150, 200, 200)
    let circularSlider = EFCircularSlider(frame: sliderFrame)
    circularSlider.addTarget(self,action:#selector(TemperatureConversion.valueChange(_:)),
                      forControlEvents:UIControlEvents.ValueChanged)

    circularSlider.minimumValue = 0
    circularSlider.maximumValue = 100
    circularSlider.currentValue = 0
    self.view.addSubview(circularSlider)
}

func valueChange(sender: EFCircularSlider){
    upperLabel.text = "\(sender.currentValue)"
}
Comments