Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 655
isaacthedev Avatar asked Jun 25 '21 19:06

isaacthedev


3 Answers

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

like image 94
Sacha.R Avatar answered Oct 14 '22 06:10

Sacha.R


Remove current Constrain and Try unchecking "Constrain to margins" button.

like image 42
Mohammed Abdul Basith Avatar answered Oct 14 '22 06:10

Mohammed Abdul Basith


Try setting a constraint to a View instead of a SafeArea

like image 27
Roma Kavinskyi Avatar answered Oct 14 '22 07:10

Roma Kavinskyi