1
votes

Is it wrong to use

viewController.view = newView;

instead of

[viewController.view addSubView:newView];

The first removes the additional level of the viewControllers automatically created view, and if I create newView like this

UIView *newView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; or like this UIView *newView = [[UIView alloc] initWithFrame:self.view.frame];

addSubview displaces the frame.origin.y by the height of the Status Bar.

Does anyone know a reason for using, or not using either method?

1

1 Answers

0
votes

Why would you want to do this? If you want to create a custom interface, you should add your subviews in the ViewControllers's -viewDidLoad method.
I do not recommend setting the VC's view outside the -loadView method.

When you add a subview and you want it to be the exact same size as the VC's view, you should not use the applicationFrame.

I would rather use [[UIView alloc] initWithFrame:self.view.frame];
Also, you should make sure to apply an autoresizing mask (flexible width & height) in case the bounds change. This would for example happen when displaying the VC in a popover.