mike vorisis mike vorisis - 1 year ago 66
iOS Question

Find where is exactly an element with swift

I want to dynamically generate textfields under my static textfield.

Let's say that I have my textfield in that position:
x: 50 y: 374 width: 220 height: 30

I used that code to see what it will return:

print(mytextfield.center.y) // 500
print(mytextfield.frame.origin.y) // 0.0

(I use swift 3)

Both wrong.

Any Ideas where am I wrong?

Thanks in advance

Answer Source

Probably you are printing from viewDidLoad, at this point of time the view haven't layout yet, you need to print this at viewWillAppear or viewDidLayoutSubview then you can get correct frame

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download