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.
Autolayout Constraints are set after
viewDidLoad()
. So you should try to print inviewDidLayoutSubviews()
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.