Questions tagged [autolayout]

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

autolayout
Filter by
Sorted by
Tagged with
1614 votes
29 answers
708k views

Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

How do you use Auto Layout within UITableViewCells in a table view to let each cell's content and subviews determine the row height (itself/automatically), while maintaining smooth scrolling ...
smileyborg's user avatar
  • 30.4k
1049 votes
12 answers
338k views

How do I animate constraint changes?

I'm updating an old app with an AdBannerView and when there is no ad, it slides off screen. When there is an ad it slides on the screen. Basic stuff. Old style, I set the frame in an animation block. ...
DBD's user avatar
  • 23.1k
721 votes
10 answers
262k views

Cocoa Autolayout: content hugging vs content compression resistance priority

I can't find a clear answer on Apple documentation regarding Cocoa Autolayout about the difference between content hugging and compression resistance. Can somebody explain their usages and ...
dmitrynikolaev's user avatar
625 votes
35 answers
366k views

UIScrollView Scrollable Content Size Ambiguity

Fellow devs, I am having trouble with AutoLayout in Interface Builder (Xcode 5 / iOS 7). It's very basic and important so I think everyone should know how this properly works. If this is a bug in ...
Wirsing's user avatar
  • 6,773
568 votes
19 answers
692k views

How to add constraints programmatically using Swift

I'm trying to figure this out since last week without going any step further. Ok, so I need to apply some constraints programmatically in Swift to a UIView using this code: var new_view:UIView! = ...
Sara Canducci's user avatar
565 votes
41 answers
431k views

How do I size a UITextView to its content?

Is there a good way to adjust the size of a UITextView to conform to its content? Say for instance I have a UITextView that contains one line of text: "Hello world" I then add another line of text: ...
drewh's user avatar
  • 10.1k
410 votes
4 answers
433k views

How to get StackPanel's children to fill maximum space downward?

I simply want flowing text on the left, and a help box on the right. The help box should extend all the way to the bottom. If you take out the outer StackPanel below it works great. But for reasons ...
Edward Tanguay's user avatar
367 votes
24 answers
214k views

How to use Auto Layout to move other views when a view is hidden?

I have designed my custom Cell in IB, subclassed it and connected my outlets to my custom class. I have three subviews in cell content which are: UIView (cdView) and two labels (titleLabel and ...
Guferos's user avatar
  • 4,357
343 votes
8 answers
96k views

Emulating aspect-fit behaviour using AutoLayout constraints in Xcode 6

I want to use AutoLayout to size and layout a view in a manner that is reminiscent of UIImageView's aspect-fit content mode. I have a subview inside a container view in Interface Builder. The subview ...
chris838's user avatar
  • 5,188
322 votes
10 answers
101k views

Automatic Preferred Max Layout Width is not available on iOS versions prior to 8.0

I opened an existing iOS project with Xcode6 beta6, and Xcode lists the following warning for both Storyboard and Xib files: Automatic Preferred Max Layout Width is not available on iOS versions ...
mono's user avatar
  • 4,341
320 votes
21 answers
162k views

Getting a "This application is modifying the autolayout engine from a background thread" error?

Been encountering this error a lot in my OS X using swift: "This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. ...
Mark's user avatar
  • 12.4k
311 votes
23 answers
116k views

What is NSLayoutConstraint "UIView-Encapsulated-Layout-Height" and how should I go about forcing it to recalculate cleanly?

I have a UITableView running under iOS 8 and I'm using automatic cell heights from constraints in a storyboard. One of my cells contains a single UITextView and I need it to contract and expand based ...
Rog's user avatar
  • 17.2k
298 votes
6 answers
149k views

How to trap on UIViewAlertForUnsatisfiableConstraints?

I'm seeing an error appear in my debugger log: Will attempt to recover by breaking constraint <NSLayoutConstraint:0x191f0920 H:[MPKnockoutButton:0x17a876b0]-(34)-[MPDetailSlider:0x17a8bc50](LTR)&...
Maury Markowitz's user avatar
293 votes
8 answers
198k views

When is layoutSubviews called?

I have a custom view that's not getting layoutSubview messages during animation. I have a view that fills the screen. It has a custom subview at the bottom of the screen that correctly resizes in ...
Steve Weller's user avatar
  • 4,609
288 votes
29 answers
144k views

Evenly space multiple views within a container view

Auto Layout is making my life difficult. In theory, it was going to be really useful when I switched, but I seem to fight it all of the time. I've made a demo project to try to find help. Does anyone ...
nothappybob's user avatar
  • 3,097
281 votes
20 answers
174k views

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's user avatar
  • 24.8k
258 votes
3 answers
95k views

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 ...
Bhumit Mehta's user avatar
  • 16.3k
252 votes
3 answers
106k views

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 ...
Andrea's user avatar
  • 26.3k
237 votes
18 answers
334k views

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 ...
rawbee's user avatar
  • 2,956
230 votes
11 answers
85k views

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 ...
Ben Packard's user avatar
  • 26.3k
206 votes
4 answers
57k views

Are NSLayoutConstraints animatable? [duplicate]

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-...
borrrden's user avatar
  • 33.3k
195 votes
21 answers
147k views

UICollectionView, full width cells, allow autolayout dynamic height?

Historic question. Note that Apple now have UICollectionViewCompositionalLayout, which is trivial to use. (Essentially just set fractionalWidth to 1.) All previous apple systems for sizing collection ...
Fattie's user avatar
  • 17.9k
191 votes
8 answers
129k views

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 ...
James Harpe's user avatar
  • 4,345
185 votes
17 answers
117k views

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 ...
tharris's user avatar
  • 2,232
177 votes
18 answers
91k views

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 ...
user1459524's user avatar
  • 3,603
170 votes
13 answers
100k views

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 ...
Ryan Romanchuk's user avatar
167 votes
12 answers
62k views

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 ...
jrturton's user avatar
  • 119k
166 votes
4 answers
37k views

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:...
user1703590's user avatar
  • 1,661
162 votes
14 answers
89k views

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 ...
Christian Schnorr's user avatar
160 votes
22 answers
56k views

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 ...
David's user avatar
  • 7,256
159 votes
13 answers
97k views

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 ...
circuitlego's user avatar
  • 3,489
153 votes
6 answers
52k views

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's user avatar
  • 2,063
148 votes
4 answers
112k views

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 ...
DAK's user avatar
  • 1,505
142 votes
10 answers
229k views

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....
Chris Mikkelsen's user avatar
141 votes
6 answers
95k views

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-...
Mete's user avatar
  • 5,555
138 votes
13 answers
105k views

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 ...
Jan Z.'s user avatar
  • 6,903
132 votes
30 answers
75k views

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 ...
blackp's user avatar
  • 1,752
131 votes
10 answers
97k views

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 ...
Jordan H's user avatar
  • 54k
131 votes
6 answers
25k views

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)? ...
Sulthan's user avatar
  • 129k
128 votes
6 answers
84k views

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 ...
Meltemi's user avatar
  • 38.2k
127 votes
18 answers
165k views

How to adjust height of UICollectionView to be the height of the content size of the UICollectionView?

I would like the UICollectionView (The red one) to shrink to the height of the content size in this case UICollectionViewCells(the yellow ones) because there is a lot of empty space. What I tried is ...
charbinary's user avatar
  • 1,895
121 votes
3 answers
66k views

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 ...
Jeffrey Berthiaume's user avatar
120 votes
8 answers
104k views

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 ...
tybro0103's user avatar
  • 49k
117 votes
5 answers
119k views

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 ...
Crashalot's user avatar
  • 34.1k
116 votes
5 answers
85k views

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, ...
yuf's user avatar
  • 3,102
115 votes
5 answers
33k views

Disable autolayout constraint error messages in debug console output in Xcode

Is there a way to (temporarily) disable autolayout error/warning messages: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you ...
Markus Rautopuro's user avatar
115 votes
29 answers
85k views

Is it possible to use AutoLayout with UITableView's tableHeaderView? [duplicate]

Since I discovered AutoLayout I use it everywhere, now I'm trying to use it with a tableHeaderView. I made a subclass of UIView added everything (labels etc...) I wanted with their constraints, then ...
ItsASecret's user avatar
  • 2,619
115 votes
31 answers
54k views

"Auto Layout still required after executing -layoutSubviews" with UITableViewCell subclass

Using XCode 4.5 and iOS 6, I'm developing an app with a simple table view with custom cells. I've done this a hundred times in iOS 5 and below, but for some reason the new autoLayout system is giving ...
Mike Mayo's user avatar
  • 1,259

1
2 3 4 5
243