Questions tagged [autolayout]

Auto Layout is a constraint-based, descriptive user interface layout system for OS X and iOS.

The Auto Layout system defines layout constraints for user interface elements. Constraints represent relationships between user interface elements such as “these views line up head to tail,” or “this button should move with this split view subview.” When laying out the user interface, a constraint satisfaction system arranges the elements in a way that most closely meets the constraints. Constraints are objects and can be established in storyboards and XIBs, exposed as outlets, and created or modified in code.

11052 questions
279
votes
20 answers

Is it possible for UIStackView to scroll?

Let's say I have added more views in UIStackView which can be displayed, how I can make the UIStackView scroll?
itsaboutcode
  • 24,525
  • 45
  • 110
  • 156
258
votes
3 answers

What is "Constrain to margin" in Storyboard in Xcode 6

I am Working with autolayout and constraints and found there is a Constrain to margins option in Xcode 6 which was not present in Xcode 5 and is checked by default. I created a test project then I added a UITableView on a ViewController with the…
Bhumit Mehta
  • 16,278
  • 11
  • 50
  • 64
249
votes
3 answers

setNeedsLayout vs. setNeedsUpdateConstraints and layoutIfNeeded vs updateConstraintsIfNeeded

I know that the auto layout chain consists in basically 3 different process. updating constraints layout views (here is where we get calculation of frames) display What's is not totally clear to me is the inner difference between -setNeedsLayout…
Andrea
  • 26,120
  • 10
  • 85
  • 131
237
votes
18 answers

UICollectionView Self Sizing Cells with Auto Layout

I'm trying to get self sizing UICollectionViewCells working with Auto Layout, but I can't seem to get the cells to size themselves to the content. I'm having trouble understanding how the cell's size is updated from the contents of what's inside the…
rawbee
  • 2,946
  • 3
  • 18
  • 22
228
votes
11 answers

Autolayout - intrinsic size of UIButton does not include title insets

If I have a UIButton arranged using autolayout, its size adjusts nicely to fit its content. If I set an image as button.image, the instrinsic size again seems to account for this. However, if I tweak the titleEdgeInsets of the button, the layout…
Ben Packard
  • 26,102
  • 25
  • 102
  • 183
206
votes
4 answers

Are NSLayoutConstraints animatable?

I am trying to animate up some views so that they are blocked by the giant keyboard in landscape. It works well if I simply animate the frames, but others have suggested that this is counter-productive and I should be updating the…
borrrden
  • 33,256
  • 8
  • 74
  • 109
194
votes
21 answers

UICollectionView, full width cells, allow autolayout dynamic height?

Note For 2021! See @Ely answer regarding UICollectionLayoutListConfiguration !!!! In a vertical UICollectionView , Is it possible to have full-width cells, but, allow the dynamic height to be controlled by autolayout? This strikes me as perhaps…
Fattie
  • 27,874
  • 70
  • 431
  • 719
191
votes
8 answers

iOS: Multi-line UILabel in Auto Layout

I'm having trouble trying to achieve some very basic layout behavior with Auto Layout. My view controller looks like this in IB: The top label is the title label, I don't know how many lines it will be. I need the title label to display all lines…
James Harpe
  • 4,315
  • 8
  • 47
  • 74
183
votes
17 answers

UITextView that expands to text using auto layout

I have a view that is laid out completely using auto layout programmatically. I have a UITextView in the middle of the view with items above and below it. Everything works fine, but I want to be able to expand UITextView as text is added. This…
tharris
  • 2,192
  • 2
  • 13
  • 14
178
votes
18 answers

How can I use Autolayout to set constraints on my UIScrollview?

I have spent two days trying out the various solutions for Mixed and Pure Autolayout approaches to achieve what was a trivial scrollview setup prior to autolayout, and it's now official - I must be too stupid. I am setting this up mostly in…
user1459524
  • 3,613
  • 4
  • 19
  • 28
170
votes
13 answers

AutoLayout with hidden UIViews?

I feel like it's a fairly common paradigm to show/hide UIViews, most often UILabels, depending on business logic. My question is, what is the best way using AutoLayout to respond to hidden views as if their frame was 0x0. Here is an example of a…
Ryan Romanchuk
  • 10,819
  • 6
  • 37
  • 41
167
votes
12 answers

How do I adjust the anchor point of a CALayer, when Auto Layout is being used?

Note: Things have moved on since this question was asked; see here for a good recent overview. Before auto layout, you could change the anchor point of a view's layer without moving the view by storing the frame, setting the anchor point, and…
jrturton
  • 118,105
  • 32
  • 252
  • 268
166
votes
4 answers

NSInvalidUnarchiveOperationException: Could not instantiate class named NSLayoutConstraint

I am very new to this. I followed Apple's tutorial step by step for the iPhone project "HelloWorld". I ran it in the iPhone 5.0 simulator and it crashed: 2012-11-02 14:46:06.782 HelloWorld[9880:c07] * Terminating app due to uncaught …
user1703590
  • 1,661
  • 2
  • 11
  • 4
162
votes
14 answers

Centering a view in its superview using Visual Format Language

I just started learning AutoLayout for iOS and had a look at Visual Format Language. It all works fine except for one thing: I just can't get a view to center within its superview. Is this possible with VFL or do I need to manually create a…
Christian Schnorr
  • 10,768
  • 8
  • 48
  • 83
159
votes
22 answers

reloadData() of UITableView with Dynamic cell heights causes jumpy scrolling

I feel like this might be a common issue and was wondering if there was any common solution to it. Basically, my UITableView has dynamic cell heights for every cell. If I am not at the top of the UITableView and I tableView.reloadData(), scrolling…
David
  • 7,028
  • 10
  • 48
  • 95