将EFCircularSlider的值更新为UILabel

时间:2016-08-07 10:33:19

标签: ios objective-c swift

我正在使用一个名为EFCircularSlider的库。它是一个ObjC库,我已成功将其导入我的项目中。但问题是我无法将滑块值更新为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

这是在ObjC中完成的。我哪里错了?

1 个答案:

答案 0 :(得分:2)

您需要在viewDidLoad方法而不是valueChange方法中添加此行。因此,请在viewDidLoad中添加此行,然后像这样更改valueChange

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)"
}