Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're going to have to specify additional constraints on the view in order to get it to size the view to fill the remaining available space. Currently, you are setting the view minimums and maximums, but not setting any concrete constraints to give autolayout a more complete solution. In addition to the upper bound for the width, you need to give it 1. a starting point to solve the width for the view by either explicitly giving it a width at a lower priority, or 2. give the spacing on either side some more rigid constraints.</p> <p>Based on what you've described, you need to constrain your view to give it some more substantial bindings to the superview on either side in order to let the system solve for the width. Since you would like to have the view size itself based on it's container's size, you will need to modify the spacing constraints (option 2 from above). In the above instance, you have specified only a minimum spacing, which would result in any of the following constraint solutions being found as valid by the autolayout engine for a 400pt superview:</p> <pre><code>|-32pt-[20pt]-------348pt-| &lt;-- autolayout will probably choose this one |-100pt----[20pt]---280pt-| |-50pt--[20pt-]-----330pt-| </code></pre> <p>Which is probably not what you are wanting. Even more still, the width of the view can be anything between 0-576pt, which is also probably not what you're wanting. Since autolayout doesn't know what you want, it's simply using the <code>intrinsicContentSize</code> of the view for concrete sizing constraints. Since you chose 32pt as the spacing, a first step would be to give the spacing constraints some more substantial instructions, namely, telling the system that the spacing <em>should be</em> 32pts between the edges of the view and the superview <em>unless</em> the width of the view is >576pts. You would do this like so in your VFL string:</p> <pre><code>"H:|-(&gt;=32,==32@900)-[viewToAdd(&lt;=576)]-(&gt;=32,==32@900)-|" </code></pre> <p>This says: "<code>viewToAdd</code> should have a maximum width of 576pts and have padding between itself and it's superview of 32pts. <em>If</em> the size of the superview grows beyond the maximum width of <code>viewToAdd</code> plus the initial padding of 64pts, the padding on either side <em>should</em> grow in order to continue to solve the constraint set."</p> <p>This results in the following constraints being correct for a 400pt superview:</p> <pre><code>|-32pt--[336pt]--32pt-| </code></pre> <p>If you would like for <code>viewToAdd</code> to remain centered in it's superview when the view grows beyond the maximum, you will have to pass in the option <code>NSLayoutFormatAlignAllCenterX</code> to the <code>options</code> parameter in <code>[NSLayoutConstraint -constraintsWithVisualFormat:]</code>. If you did not have the <code>&gt;=32</code> constraint set on the padding, or did not set a priority lower than 1000 ("required" constraint priority level) on your padding's <code>==32</code> constraint, then your superview would be unable to grow beyond 640pts.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload