Search code examples
iosswiftxcodeuisplitviewcontroller

Swift - UIButton is not pinning to the bottom of the screen


I am having trouble pinning the UIButton to the bottom of my UIViewController, (There is a tab bar if that helps). Here are the constraints of the UIButton.

enter image description here

Originally, it all worked fine, but ever since I added iPad support to the application I have issues. on the iPad the UIButton is pinned to the bottom of the screen, directly above the tab bar. However on iPhone, there is this empty gap at the bottom. enter image description here

What I Tried Doing some research I saw that sometimes split view controller causes a grey bar, I added this line of code to resolve it and it fixed the bottom bar , but this constraint issues is still causing me a headache.

self.extendedLayoutIncludesOpaqueBars = true

iPad View Hierarchy

enter image description here

iPhone View Hierarchy


Solution

  • You have an option on Xcode to vary your constraint depending of the size of the screen.

    You can create two constraints, one that works on iPad, one that works on "classic" iPhone.

    enter image description here

    Here, if I create a new constraint during the variation, I can then select on the right window which variation you want the constraint to be installed on.

    There is a whole topic about that here

    enter image description here