2016-08-07 53 views
1

我正在使用名爲EFCircularSlider的庫。這是一個ObjC庫,我已經成功將它導入到我的項目中。但問題是我無法將滑塊值更新爲UILabel將EFCircularSlider的值更新爲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完成。我哪裏錯了?

回答

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

Got it!非常感謝:) –

+0

歡迎隊友:)快樂編碼:) –

+0

問題在於你在'valueChange'方法中將'currentValue'設置爲0。 –