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.

10814 questions
1556
votes
28 answers

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 performance?
smileyborg
  • 29,421
  • 10
  • 57
  • 72
992
votes
12 answers

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. New style, I have a IBOutlet to the auto-layout…
DBD
  • 22,215
  • 12
  • 57
  • 84
662
votes
8 answers

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 difference ?
dmitrynikolaev
  • 8,436
  • 4
  • 27
  • 43
558
votes
34 answers

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 Xcode, it is a critical one! So, whenever I have a…
Wirsing
  • 6,104
  • 3
  • 13
  • 13
539
votes
41 answers

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: "Goodbye world" Is there a good way in Cocoa…
drewh
  • 9,795
  • 7
  • 30
  • 41
503
votes
19 answers

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! = UIView(frame: CGRectMake(0, 0, 100,…
Sara Canducci
  • 5,571
  • 5
  • 17
  • 23
380
votes
4 answers

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 of layout (I'm inserting UserControls dynamically)…
Edward Tanguay
  • 176,854
  • 291
  • 683
  • 1,015
346
votes
24 answers

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 emailLabel). Depending on data available for each row,…
Guferos
  • 4,147
  • 5
  • 15
  • 23
342
votes
8 answers

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 has some inherent aspect ratio which I wish to…
chris838
  • 5,118
  • 5
  • 21
  • 26
322
votes
10 answers

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 prior to 8.0 I tried addressing the warning by…
mono
  • 4,249
  • 2
  • 16
  • 36
313
votes
21 answers

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. This will cause an exception in a future release." I…
Mark
  • 11,575
  • 4
  • 18
  • 35
284
votes
29 answers

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 know how to make the spaces between views…
nothappybob
  • 3,027
  • 4
  • 13
  • 14
280
votes
19 answers

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 on user input - tap to shrink/expand the…
Rog
  • 16,650
  • 9
  • 48
  • 73
274
votes
8 answers

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 Interface Builder if I change the height of the nav…
Steve Weller
  • 4,409
  • 4
  • 20
  • 30
269
votes
5 answers

How to trap on UIViewAlertForUnsatisfiableConstraints?

I'm seeing an error appear in my debugger log: Will attempt to recover by breaking constraint Make a symbolic breakpoint at…
Maury Markowitz
  • 8,303
  • 8
  • 36
  • 79
1
2 3
99 100