Varis Darasirikul
Varis Darasirikul

Reputation: 3063

How to find the position of UITextField by Swift?

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!

Upvotes: 3

Views: 8698

Answers (2)

Manikandan D
Manikandan D

Reputation: 1442

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) ")

Upvotes: 9

IamMashed
IamMashed

Reputation: 1849

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.

Upvotes: 2

Related Questions