Reputation: 461
UIView *view =[[UIView alloc] initWithFrame:CGRect(0,0,300,70)]; //--(View created)
someViewController *someViewControllerObject = [..]; //View Controller Object created.
[view addSubview:[someViewControllerObject.view]];
I want to fit the view controller's view in the UIView's object. The above code doesn't work correctly. Can you help me figure this out?
Upvotes: 0
Views: 2162
Reputation: 303
This code will make it the same size as your current view.
someViewControllerObject.view.frame = view.bounds;
[view addSubview:[someViewControllerObject.view]];
Upvotes: 0
Reputation: 21967
@david's answer is correct to set the initial frame of the view controller's view. set the autoResizingMask
to get the behavior you want when the superview changes.
someViewControllerObject.view.frame = view.bounds;
someViewControllerObject.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[view addSubview:someViewControllerObject.view];
Upvotes: 1
Reputation: 801
The simplest would be to just set the frame of the controller view to the bounds of the outer view;
UIView *view =[[UIView alloc] initWithFrame:CGRect(0,0,300,70)]; //--(View created)
someViewController *someViewControllerObject = [..]; //View Controller Object created.
someViewController.view.frame = view.bounds;
[view addSubview:[someViewControllerObject.view]];
Upvotes: 1