How can i get the imageView's size from storyboard?

294 views Asked by At

I add a imageView in storyboard, and add a few constraints(Trailing,Leading, Bottom, Top, Ratio).Now i want to get imageView size in code. NSlog("%f", cell.imageView.frame.size.width); But, when i run it in iPhone5, the result is the same as that run in iphone6. what should i do , thank you very much(Xcode6, iOS sdks 8.1).

i have resolved it, when i moved the "cell.frame.size.width" to viewDidLayoutSubviews.

2

There are 2 answers

2
Sahil Kapoor On BEST ANSWER

Autolayout Constraints are set after viewDidLoad(). So you should try to print in viewDidLayoutSubviews() or later in view controller lifecycle. Otherwise, you might have applied constraints (may be with respect to other views or as Nilesh states, equal width/height/aspect ratio) that force size to remain the same.

0
kygcoleman On

Make sure you have autolayout turned on (easiest way possible) and set constraints to the imageView that is in the .storyboard file. Look for this button in the bottom right corner of the standard editor when you are viewing the .storyboard file enter image description here