12

I am accessing the size of the frame of view from storyboard. Below is my code for accessing frame property from storyboard.

SmallView *smallView = [self.storyboard instantiateViewControllerWithIdentifier:@"SmallView"];
CGRect frame = smallView.view.frame;
self.containerView.frame = frame;

In story board the frame size of the view is (200,400). But when I am accessing the frame size from the code it's always giving (320,460).Why? In the above code I got small view object from storyboard so what will be the value of view's frame in story board that should be shown but it's not showing.Always it's showing (320,460).

For quick debugging you can check the below source code .

https://dl.dropbox.com/u/90940570/FrameTest.zip

1
  • AutoLayout? autoresizeSomething (don't remember the exact term) of the view at YES, whereas putting it a NO should work?
    – Larme
    Jan 25, 2013 at 11:42

2 Answers 2

41

Uncheck the "Resize View From Nib" box in the inspector. That should give you the correct size for a freeform view controller.

2
  • Thank you, thank you! I was just about to pull my hair out over this simple checkbox issue and it is exactly what was wrong with mine.
    – Sepui
    Mar 27, 2013 at 17:09
  • Many thanks for the tiny but paining thing to resolve. Dec 23, 2015 at 10:05
0

Gettings a frame of a viewController's view which might not even displayed is not a good practice. The point where you can assume, everything is in place is the viewControllers's ViewDidLoad method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.