2015-07-20 50 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)键和移动你的鼠标指针。 您将看到红线,指示您指向的任何距离。