我正在使用一个名为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)"
}
这是在ObjC中完成的。我哪里错了?
答案 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)"
}