How do you use autolayout to position a button at the bottom of a scrollview?

Discussion in 'iOS Programming' started by whitedragon101, May 29, 2014.

  1. whitedragon101 macrumors 65816

    Sep 11, 2008
    I have a viewcontroller that contains a view which contains a scrollview which contains my content i.e

    - View > ScrollView -> text feild

    This is so when I tap in the text field the content moves up and the keyboard doesn't cover the text field.

    Now I come to use autolayout I add constraints for the scrollview for 0,0,0,0 for leading, trailing (to container), top, bottom (to top bottom layout guide). It duly fills the screen on a 3.5" or 4" screen. So for so good.

    The problem comes when add a constraint for the text field to 5px for "bottom space to container." It does nothing. I would be grateful for any help to lay out objects in the scrollview.
  2. waterskier2007 macrumors 68000


    Jun 19, 2007
    Novi, MI
    This could be because the scrollview has no intrinsic contentSize. I usually set up my scrollviews programmatically, and therefore do something like

    _scrollView.contentSize = CGSizeMake(500, 500)
    If the scrollView has no contentSize set yet, it doesn't know the size of all of the stuff that it contains (because a UIScrollView can contain stuff larger than its own bounds).

Share This Page