sam
sam

Reputation: 461

Setting size of viewController's view in UIView

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

Answers (3)

David Y.
David Y.

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

XJones
XJones

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

Kenny Lövrin
Kenny Lövrin

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

Related Questions