mike vorisis mike vorisis - 1 month ago 7
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

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