Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Subview to fill parent

I have some subviews that I place inside each of my tab bar's view controllers. Right now I'm sizing it with a pixel count but it only works on the iPhone 4 and 4s and not the iPhone 5 because of the longer screen size. I could check for the device and then size it that way but I feel like there has to be an easier way to do this.

viewController1.view.frame = CGRectMake(0, 0, 320, 460);

I colored the subview yellow so it's easier to see.

enter image description here

like image 451
centree Avatar asked Jun 20 '13 14:06

centree


People also ask

How do I find the parent of a subform or report?

Remarks You can use the Parentproperty to determine which form or report is currently the parent when you have a subform or subreport that has been inserted in multiple forms or reports. For example, you might insert an OrderDetailssubform into both a form and a report.

How do I make a view fill the screen?

TLDR: To make a view fill the screen or parent view, you can set the maxHeight and maxWidth to .infinity when using the frame view modifier. I am going to start off with a very basic layout, the code will look like this:

How to make a view fill a space in SwiftUI?

It is often required that a view fill a space, whether it is width, height or both. Luckily for us SwiftUI makes this very easy to do. TLDR: To make a view fill the screen or parent view, you can set the maxHeight and maxWidth to .infinity when using the frame view modifier.

How to add iOS subview in iOS app?

The first button implement addsubview function, when you click the first button it will add a subview object to the screen. The second button implement removes the subview function, when you click the second button it will remove the added subview by the first button. 2. Add iOS SubView Code Steps.


2 Answers

  1. You should NOT change frame of tabbar's content view controller's view. UITabBar takes itself care of sizing the child view controller's frame properly.
  2. If you want to add subview to content view controller (controller under some tab) and make that view to always automatically resize with the controllers main view (self.view), you can use combination of superviews frame and autoresizing.

Example code (you can do this in - (void)viewDidLoad for example):

UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:view];
like image 91
Lukas Kukacka Avatar answered Oct 16 '22 07:10

Lukas Kukacka


If you want to do this by setting frame than DO this:

[childView setFrame:childView.superview.bounds];
like image 27
CRDave Avatar answered Oct 16 '22 08:10

CRDave