mike vorisis
mike vorisis

Reputation: 2832

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

Upvotes: 0

Views: 58

Answers (1)

Tj3n
Tj3n

Reputation: 9943

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

Upvotes: 2

Related Questions