How do you keep a button at the bottom of the screen for 3.5 & 4 inch displays?

Discussion in 'iOS Programming' started by whitedragon101, Feb 24, 2014.

  1. whitedragon101, Feb 24, 2014
    Last edited: Feb 24, 2014

    whitedragon101 macrumors 6502a

    Joined:
    Sep 11, 2008
    #1
    Here is what I have done.

    I have a standard viewController in the storyboard set to 3.5inch display. Then i drag in a view make it the full size of the screen and set its colour to blue. I drag in a button to the view and set a single constraint
    - bottom space to bottom layout guide = 20

    I run this in the simulator using a 4 inch screen and the view has automatically expanded to fit the whole size and the button has moved to the bottom of the larger screen with it . Great.

    Now I add a scrollview I set the it to pin top and bottom. I create a button and place it at the bottom of the scrollview and set it to pin bottom (the bottom constraint distance). When I run it the scrollview scales and increases in size to fit the 4 inch screen BUT the button stays where it is.

    Any ideas how I can get the bottom to stay pinned to the bottom of the scrollview as it scales?
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    I believe I saw this in one of the WWDC videos on using AutoLayout (can't remember which session or year) but you should make a separate view to be the contents of your scroll view, layout everything you want in it, and then at runtime load that separate view into your scroll view.
     
  3. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #3
    I'm not using the auto layout function, cus somehow its not working great.
    Some video tutorials shown the great part of it, however I'm still not getting it.
    With a load workarounds with adding constraints and stuff, I turn off auto-layout.

    In the storyboard, go to File Inspector, and turn of 'Use Autolayout'.
    Then for each object you have, i.e. an button you want to stick at the bottom, no matter how big the screen is, go to the size inspector and you will see your having an extra option for 'Autosizing'. For here you can chose if it should be scaling along the width or height, and the pin positions, top, left, right and bottom.

    Just uncheck the top pin, and check the bottom.

    And for example you are showing an imageview, which is a bit out of the top, bottom and sides. And you want it to scale with the screens, but keep the offsets, click all pins and click both scaling options. :)

    Its great!

    That's all for it for now. It helped me alot and made me got rid of loads warnings about constraints missing and stuff..

    cheers!
     

Share This Page