6

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

isaacthedev
  • 181
  • 10
  • 1
    Try unchecking "Constrain to margins" – aheze Jun 25 '21 at 19:14
  • already tried that – isaacthedev Jun 25 '21 at 19:21
  • Click on the downwards arrow next to `0` in your screenshot, make sure it's set to "View" – aheze Jun 25 '21 at 19:22
  • 1
    What does your view hierarchy look like? What are you pinning the the bottom constraint to? ScrollViews in particular can cause issues with pinning with discrepancies between iphone and iPad potentially being caused by hard coded values in other parts of the view. – Eric Shieh Jun 25 '21 at 19:40
  • @ericshieh The issue is if I pin it to the view (superview) it works on the iPhone, but on the iPad it is hidden behind the tab bar. If I pin it to the safe area, it works on iPad but there is a gap on the iPhone. – isaacthedev Jun 28 '21 at 16:16
  • But what does the entire view hierarchy look like? It helps answered recreate your issue instead of speculating. – Eric Shieh Jun 28 '21 at 20:27
  • @EricShieh I just updated my question with the view hierarchy. – isaacthedev Jun 29 '21 at 01:19
  • 1
    @isaacthedev you've added ipad VH, but iphone one is missing – Phil Dukhov Jun 30 '21 at 02:26
  • Its hard to debug when we're given inconsistent information: The view hierarchy you sent doesn't match the problem image you've posted. FWIW, i did a quick experiment in a test app re-creating the view hierarchy you posted (A split view contained within a tab view controller) and the button pinned at the bottom in iPhone and iPad with no problem and no special adjustments required. – Eric Shieh Jun 30 '21 at 04:02
  • 2
    If possible please add demo project link – Raja Kishan Jun 30 '21 at 07:58
  • I would also encourage you to try out AutoLayout instead of Storyboards. They are better at both structuring and building your views, as well as asking for code reviews. – Linus Jul 01 '21 at 13:47
  • 1
    @isaacthedev please share the controller xml. – jatin fl Jul 03 '21 at 06:29

4 Answers4

4

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

Sacha.R
  • 394
  • 2
  • 17
1

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

1

Try setting a constraint to a View instead of a SafeArea

Roma Kavinskyi
  • 268
  • 4
  • 12
0

1- Give it a constant height for example 40

2- While setting constraints, uncheck (Constrain to margins)

3- Give it a proportional width constraint with the super view 0.8

Note1: If you don't want to give it a fixed height you can do the same step 3 but with height and not 0.8 but maybe 0.2 to less depending on your design.

Note2: You can use a scroll view, it will make it so easy for you

Menaim
  • 937
  • 7
  • 28