Autolayout constraints!!?

Discussion in 'iOS Programming' started by DennisBlah, Feb 4, 2015.

  1. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    Hi all,

    I know I'm sounding noobish now.. But.. How does these constraints work ?

    Lets say I have an 'header' view.
    I want this header view stay the same height as it is. So I add the constraint to "Pin" the height.
    Now I want to to be as width as the self.view.. So I rightlcick my 'header' to 'view' and say equal width.
    Doing the same for leading space, and top space.

    So now I have set constraints for top, left, width and height.

    Left and Top of 'header' is 0.

    I have a preview of 4.5" 5" and iPad, on the iPad I see that there is space between the left and my header, 20 ? or little less, but more than default -16

    Can anyone help me out, if someone understands what I'm talking about ?
     
  2. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #2
    Hi all,

    is there someone that can explain this to me ?

    On iPhone's I need to use Leading space -16
    On an iPad I need to use Leading space 0

    How can I fix this ?
    This is pretty urgent and starts to annoy me big time now.

    I'm taking leadingspace from the self.view
     
  3. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #4
    I did, but nowhere is mentioned difference between autolayout constraints for iPad and iPhone.

    On iPhone it's fine, on iPad I need to change Leading horizontal space to -20, but then I'm getting an gap at the right side on the iPhone.

    Shouldn't Leading horizontal space be 0, equal width of the 'view' / self.view ?
    Then I even get a bigger gap at the left.

    Anyone please advice what to do about this.
     
  4. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #5
    Are you sure you aren't confusing "leading space to container" and "leading space to container margin"?

    In iOS 8 Apple added a container margin. You can override this by holding the option key after you ctrl+drag out your constraints. If you set your constraint to the container margin = 0, then it's going to be 16 points from the edge of the actual container. However, if you hold option and select to set the constraint relative to the container = 0, it will be at the edge of the container.
     
  5. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #6
    \o/
    bless you!!!!!!!
    Kudoosssssss
     
  6. waterskier2007 macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #7
    No problem. It's quite annoying and I wish the defaults were switched, but once you learn about it, it becomes instinct.
     

Share This Page