2015-07-20 49 views
2

如何找到Swift的UITextField的位置?如何通過Swift找到UITextField的位置?

我想知道我的UITextField和底部位置之間的距離。

謝謝!

+1

見http://stackoverflow.com/questions/7028850/ios-get-location-of-a-view-in-a-window –

+0

你到底想幹什麼? –

+0

我想將每個關閉的文本字段都改爲正確的距離。 –

回答

7

試試這個,

讓你的文本框位置在你的程序中。

println("Your textfiled position : \(textfiled.frame)") // (x,y,width,height) 

要在您的程序中獲得您的BottowView位置。

println("BottomView position : \(bottomview.frame)") // (x,y,width,height) 

獲得兩個位置之間的距離。

println("Distance x:(textfiled.frame.origin.x - bottomview.frame.origin.x) ") 
println("Distance y:(textfiled.frame.origin.y - bottomview.frame.origin.y) ") 
println("Distance width:(textfiled.frame.size.width - bottomview.frame.size.width) ") 
println("Distance height:(textfiled.frame.size.height - bottomview.frame.size.height) ") 
2

在故事板:

選擇的UITextField ... 按住Alt(Option)鍵和移動你的鼠標指針。 您將看到紅線,指示您指向的任何距離。