3

How can I find the position of UITextField by Swift?

I want to know the distance between my UITextField and the bottom position of view.

Thanks!

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152
Varis Darasirikul
  • 3,013
  • 5
  • 25
  • 35

2 Answers2

9

Try this,

To get your textfield position in your program.

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

To get your BottowView position in your program.

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

To get Distance between two position.

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) ")
Manikandan D
  • 1,422
  • 1
  • 13
  • 25
2

In the storyBoard:

Select the UITextField... Hold Alt (Option) key and move your mouse pointer. You will see red lines indicating the distance to whatever you are pointing at.

IamMashed
  • 1,811
  • 2
  • 21
  • 32