-2

This should be a very basic question, but I have tried a lot of things and it isn't working. :/

I have a single view application which consists of a single, full-screen custom view. I had my view class set on the main view of the view controller, but the status bar was always overlaid on my view.

Apple says to fix this, constrain your view to the top layout guide, but that requires I move my view to be a child of the main view. So I moved it, but now I can't set up constraints to simply make my view fill 100% of vertical and horizontal space.

I have tried doing it in code, using constraints, stacked views, anything I can find, but to no avail.

So, the hopefully simple question is, how can I make a single UIView child of the main view of a view controller size to fill the container and account for the status bar? The UIView is a custom class, so if code is needed I can do that.

I have tried overriding the intrinsic and size that fits methods, but they created terrible results.

absmiths
  • 1,144
  • 1
  • 12
  • 21

2 Answers2

1

You can do this programmatically:

  let childView: UIViewCustom = UIViewCustom()
  childView.frame = rootView.frame
  childView.bounds = rootView.bounds
  rootView.addSubview(childView)

Or via IB: first select your childView, then click on the pin button in the low-right corner of XCode, disable Constrain to margins, then click on each red bar and set to zero the constrain. Finally click on Add 4 Constraints

Hope it helps.

Adda_25
  • 498
  • 7
  • 12
0

try this:

0.Assume that you have a custom class just for View (not ViewController) named AAA.

  1. in Main.storyboard, drag a "View" from Object Library to your ViewController. Call it ViewB.

2.set the viewB layout and constrains

3.select the viewB and go to its identify inspector(3rd small button on the right panel)

4.in the class section: write it as: AAA

Hope this will help you.