I am developing using iOS 6 auto layout
I would like to log a message displaying the frame width of the view.
I can see the textView on the screen.
But I get the width and height as zero, am I missing something ?
NSLog(@"textView = %p", self.textView);
NSLog(@"height = %f", self.textView.frame.size.height);
NSLog(@"width = %f", self.textView.frame.size.width);
textView = 0x882de00
height = 0.000000
width = 0.000000
I think auto layout hasn't had the time to layout your views by the time you call this. Auto layout hasn't happened by the time viewDidLoad
is called, because it's called just after the views are loaded and it's only after that that the views are placed into the view controller's view hierarchy and eventually laid out (in the view's layoutSubviews
method).
Edit: this answer points out why the scenario in the question doesn't work. @dreamzor's answer points out where to place your code in order to solve it.