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
159
votes
13 answers

UILabel sizeToFit doesn't work with autolayout ios6

How am I supposed to configure programmatically (and in which method) a UILabel whose height depends on its text? I've been trying to set it up using a combination of Storyboard and code, but to no avail. Everyone recommends sizeToFit while…
circuitlego
  • 3,469
  • 5
  • 22
  • 22
153
votes
6 answers

Enabling auto layout in iOS 6 while remaining backwards compatible with iOS 5

What is the best way to take advantage of the new auto layout features of iOS 6 while still providing compability with older devices on earlier versions of iOS?
sglantz
  • 2,063
  • 4
  • 20
  • 30
148
votes
4 answers

How to resize superview to fit all subviews with autolayout?

My understanding of autolayout is that it takes the size of superview and base on constrains and intrinsic sizes it calculates positions of subviews. Is there a way to reverse this process? I want to resize superview on the base of constrains and…
DAK
  • 1,505
  • 3
  • 11
  • 5
141
votes
6 answers

autolayout - make height of view relative to half superview height

have been getting into autolayouts recently and I'm stuck on what seems like a really trivial problem example. I have a view that I want to sit at the top of the screen, and take up half of the screen-height. Simple before autolayout - just tack it…
Mete
  • 5,495
  • 4
  • 32
  • 40
139
votes
10 answers

How to update the constant height constraint of a UIView programmatically?

I have a UIView and I set the constraints using Xcode Interface Builder. Now I need to update that UIView instance's height constant programmatically. There is a function that goes like myUIView.updateConstraints(), but I don't know how to use it.
Chris Mikkelsen
  • 3,987
  • 9
  • 29
  • 41
137
votes
13 answers

How to determine height of UICollectionView with FlowLayout

I've got an UICollectionView with an UICollectionViewFlowLayout, and i want to calculate its content size (for return in intrinsicContentSize needed for adjusting its height via AutoLayout). The problems is: Even if I have a fixed and equal height…
Jan Z.
  • 6,883
  • 4
  • 23
  • 27
132
votes
30 answers

UITableView dynamic cell heights only correct after some scrolling

I have a UITableView with a custom UITableViewCell defined in a storyboard using auto layout. The cell has several multiline UILabels. The UITableView appears to properly calculate cell heights, but for the first few cells that height isn't properly…
blackp
  • 1,752
  • 3
  • 13
  • 14
131
votes
6 answers

What happens with constraints when a view is removed

The question I have is simple but I couldn't find any information in the documentation. What happens with layout constraints when a view is removed from the view hierarchy (or moved to another view)? For example, let's have container C with subviews…
Sulthan
  • 128,090
  • 22
  • 218
  • 270
130
votes
10 answers

Is it possible to obtain a dynamic table view section header height using Auto Layout?

New in iOS 8, you can obtain 100% dynamic table view cells by simply setting the estimated row height, then layout your elements in the cell using Auto Layout. If the content increases in height, the cell will also increase in height. This is…
Jordan H
  • 52,571
  • 37
  • 201
  • 351
127
votes
6 answers

iOS: How does one animate to new autolayout constraint (height)

I've never worked with autolayout constraints before. I have a small new app I'm working on and noticed that the NIB's views are defaulting to autolayout. So, I figured I'd take the opportunity to work with it and try to figure out where Apple is…
Meltemi
  • 37,979
  • 50
  • 195
  • 293
121
votes
3 answers

How to create percentage of total width using autolayout?

I need to create three dynamic columns, each with a fixed percentage of the total width. Not thirds, but different values. For example, the following illustration shows three columns: the first being 42% wide, the second being 25% wide, and the…
Jeffrey Berthiaume
  • 4,054
  • 3
  • 35
  • 45
117
votes
8 answers

When can I activate/deactivate layout constraints?

I've set up multiple sets of constraints in IB, and I'd like to programmatically toggle between them depending on some state. There's a constraintsA outlet collection all of which are marked as installed from IB, and a constraintsB outlet collection…
tybro0103
  • 48,327
  • 33
  • 144
  • 170
116
votes
5 answers

Use Storyboard to mask UIView and give rounded corners?

Lots of questions like this explain how to programmatically create a mask and provide rounded corners to a UIView. Is there a way to do it all within Storyboard? Just asking because it seems like creating rounded corners in Storyboard keeps a…
Crashalot
  • 33,605
  • 61
  • 269
  • 439
116
votes
5 answers

How can I get a view's current width and height when using autolayout constraints?

I'm not talking about the frame property, because from that you can only get the view's size in the xib. I'm talking about when the view is resized because of its constraints (maybe after a rotation, or in response to an event). Is there a way to…
yuf
  • 3,082
  • 3
  • 20
  • 18
115
votes
5 answers

Specifying one Dimension of Cells in UICollectionView using Auto Layout

In iOS 8 the UICollectionViewFlowLayout supports automatically resizing cells based on their own content size. This resizes the cells in both width and height according to their content. Is it possible to specify a fixed value for the width (or…
Anthony Mattox
  • 7,048
  • 6
  • 43
  • 59