Reputation: 1965
When i am placing view of frame size (0.0,0.0,320.0,435.0)
applying auto layout it appears proper in iphone 5 (4 inch) and when i am running in iphone 4s it appears proper due to autolayout but when i am fetching value of its frame after execution during run time it appears "(0.0,0.0,320.0,435.0)"
I cannot get size which have change after applying auto layout in iphone 4s?
I want to get size because using that size i can set programmatically size of custom view created.
Upvotes: 7
Views: 6383
Reputation: 6882
Before your "getting real size code", insert the following code:
yourView.setNeedsLayout()
yourView.layoutIfNeeded()
Upvotes: 18
Reputation: 3393
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 layouted (in the view's layoutSubviews method).
try this code
//delegate method
- (void) viewDidLayoutSubviews
{
NSLog(@"height=%f",self.myview.frame.size.height);
}
Upvotes: 9