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
  • 50,715
  • 11
  • 102
  • 148
Varis Darasirikul
  • 2,863
  • 5
  • 24
  • 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,382
  • 1
  • 12
  • 24
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,709
  • 2
  • 17
  • 31