Setting Grid Size in Container View


Greetings Programs!

I have a grid in a container view and need to restrict the size of the grid to the bounds of the container view.

I am using this so far to set it:

    shinobiDataGrid = [[ShinobiDataGrid alloc] initWithFrame:CGRectInset(CGRectMake(0, 0, self.view.frame.size.width, 243), 0,0)];




 shinobiDataGrid = [[ShinobiDataGrid alloc] initWithFrame:CGRectMake([containerView bounds])];


The problem is that I have a SplitViewController and the ContainerView is in the DetailViewController with the grid view embedded via Storyboard.

I am trying to use the following to get the bounds but it’s still not working.

SCViewController *dashboard = (SCViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
	if (dashboard == [[self navigationController].viewControllers objectAtIndex:0])
		UIView *gridContainer = (UIView *)[dashboard.view viewWithTag:5];
		NSLog(@"Bounds: %f, %f", gridContainer.frame.size.width, gridContainer.frame.size.height);

		shinobiDataGrid = [[ShinobiDataGrid alloc] initWithFrame:CGRectInset([gridContainer bounds], 0, 0)];
		CGRect rect = CGRectMake(0, 0, self.view.frame.size.width, 300);
		NSLog(@"Bounds: %f, %f", rect.size.width, rect.size.height);

		shinobiDataGrid = [[ShinobiDataGrid alloc] initWithFrame:CGRectInset(rect, 0, 0)];




Can you provide more details about what is ‘not working’? Its hard to tell what is going wrong without a detailed description or screenshot.

Have you tried what sprior suggested, and then setting an autoresizing mask on your grid so it can change size to fit the container view? Something like this:

[grid setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];