2016-04-21 19 views
0

我正在處理我的應用程序,我需要幫助UITextFieldtextField上的位數

我想知道UITextField上顯示的數字是從1到0的範圍內的滑塊值(我需要這個範圍),看起來是特定的數字(例如3)與他們之間的數字(0.5,0.6 ...)。

我得到的數字是6位數字(0.123456),我希望它顯示的更少。

我已經試過這funcion後添加UITextFieldDelegate

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool 
{ 
... 
} 

但它不工作。我得到了幫助一些一個使用此功能:

@IBAction func testField(sender: UITextField) { 
    let TheLength = sender.text!.characters.count 
    if TheLength = >= 3 { 
     let TheRange = Range(start: sender.text!.startIndex, end: sender.text!.startIndex.advancedBy(3)) 
     var newdi = sender.text!.substringWithRange(TheRange) 
     sender.text = newdi 
    } 
} 

也沒什麼改變。

注:我有更多UITextFields來解決。

+0

要清楚,你希望你的滑塊從0到1,以0.1爲增量。所以它變爲0.0,0.1,0.2等,最高可達1.0。 – ryantxr

回答

0

使用它這樣的東西。

textField.text = String(format: "%0.1f", slider.value) 
+0

謝謝你的工作 – Fatmah

相關問題