1

I have UIView where a UIStackView is a subview. Normally it fills the UIView. However, when I embed the UIView in a UINavigationController the UIView and UIStackView no longer extend to the bottom of the screen. It seems that they are getting a height that is only necessary to contain the UIStackView's subviews and nothing more. Here's what the constraints code looks like:

func setContraints() {

    readableContentGuide.topAnchor.constraint(equalTo: stackView.topAnchor, constant: 0.0).isActive = true
    readableContentGuide.bottomAnchor.constraint(equalTo: stackView.bottomAnchor, constant: 0.0).isActive = true
    readableContentGuide.leadingAnchor.constraint(equalTo: stackView.leadingAnchor, constant: 0.0).isActive = true
    readableContentGuide.trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: 0.0).isActive = true

    stackView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor)
    stackView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)

}

This line from above has no effect:

stackView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)

And here is how I'm setting up the UINavigationController in AppDelegate:

window = UIWindow()
    let homeViewController = BeginCheckoutViewController()
    let navController  = UINavigationController(rootViewController: homeViewController)
    self.window?.rootViewController = navController
    window?.makeKeyAndVisible()
bhartsb
  • 1,316
  • 14
  • 39

2 Answers2

0

We got a similar problem only on iPhoneX. Have you tried a different simulator? Maybe it's the same problem.

Try to use the bottomAnchor instead of safeAreaLayoutGuide.bottomAnchor: stackView.bottomAnchor.constraint(equalTo: bottomAnchor)

On iPhoneX the safeAreLayoutGuide.bottomAnchor is not identical with the bottomAnchor because of the round edges (else there might be content missing). So if you do not have a UITabBar or something at bottom of your screen that fill the gap, this might help.

ObjectAlchemist
  • 1,109
  • 1
  • 9
  • 18
  • I tried a different simulator and also have been running on my iPhone 6s. The behavior is the same when I try what you suggested. – bhartsb Aug 06 '18 at 04:19
0

Try this:

stackView.setCustomSpacing(100, after: YourLastItemInStackview)

OR

You can add an empty UIView as a last item of stack view with the height you expect for bottom margin.