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
76
votes
18 answers

How do I programmatically set device orientation in iOS 7?

I am working on an iPad app, using AutoLayout, where if the user enables a certain mode ("heads-up" mode), I want to support only portrait (or portrait upside down) orientation, and furthermore, if the device is in landscape, I'd like to…
John Stewart
  • 1,176
  • 1
  • 10
  • 22
74
votes
4 answers

Add spacing constraint to superview in Xcode 5

I am building an iOS app in Xcode 5, and I'm having trouble adding layout constraints. In Xcode 4.x, I could just add leading/trailing/top/bottom spaces to container (superview) to any UI element. Now, I only have this option: I want to add a…
Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
72
votes
8 answers

With Auto Layout, how do I make a UIImageView's size dynamic depending on the image?

I want my UIImageView to grow or shrink depending on the size of what the actual image it's displaying is. But I want it to stay vertically centered and 10pts from the leading edge of the superview. However, if I set these two constraints it…
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
72
votes
1 answer

setNeedsLayout and setNeedsDisplay

What is the real difference between UIView methods setNeedsLayout and setNeedsDisplay? As usual documentation is foggy about this.
Duck
  • 34,902
  • 47
  • 248
  • 470
71
votes
3 answers

When should translatesAutoresizingMaskIntoConstraints be set to true?

I've read the documentation. But I'm still not sure when I need to not set it to false. In the code below if I set it to false I won't see the header at all. If I leave it as true, then everything is fine. The following in View debug hierarchy will…
mfaani
  • 33,269
  • 19
  • 164
  • 293
71
votes
5 answers

Can I use setFrame and autolayout on the same view?

I want to add padding to all of my buttons, so I subclassed UIButton, and among other changes, I wanted to add a fixed padding by using setFrame method. Everything was working, except for setFrame. I checked around, and I found out that if I…
SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
70
votes
1 answer

Difference between NSLayoutAttributeLeft vs NSLayoutAttributeLeading

What is the difference between NSLayoutAttributeLeft and NSLayoutAttributeLeading in iOS autolayouts?
Raj iOS
  • 1,047
  • 1
  • 9
  • 20
70
votes
11 answers

topLayoutGuide in child view controller

I have a UIPageViewController with translucent status bar and navigation bar. Its topLayoutGuide is 64 pixels, as expected. However, the child view controllers of the UIPageViewController report a topLayoutGuide of 0 pixels, even if they're shown…
hpique
  • 119,096
  • 131
  • 338
  • 476
69
votes
8 answers

Auto Layout (Constraints) Center 2 side by side views in a parent view

I'm trying to figure out how to do this with auto layout (iOS6) and constraints. Basically I have my large view divided up into two sections on the bottom. Inside of those sections (currently subviews) I have an image view and a label. I want to…
Bob Spryn
  • 17,742
  • 12
  • 68
  • 91
68
votes
17 answers

Vertically align text within a UILabel (Note : Using AutoLayout)

I am Copying the same Question asked Before Question. I have tried the solutions given and was not able to solve it since sizetofit was not effective when I use Autolayout. The expected display is like below.
MELWIN
  • 1,093
  • 4
  • 12
  • 19
68
votes
1 answer

Proper usage of intrinsicContentSize and sizeThatFits: on UIView Subclass with autolayout

I'm asking this (somehow) simple question just to be finicky, because sometimes I'm worried about a misuse I might be doing of many UIView's APIs, especially when it comes to autolayout. To make it super simple I'll go with an example, let's assume…
dev_mush
  • 2,136
  • 3
  • 22
  • 38
68
votes
3 answers

Auto Layout to dynamically size uilabel width

So I have two UILabels side by side in Storyboard. The second label should butt up against the right edge of the first one (trailing constraint of 1), but I also need the first label (the one on the left) to set it's width equal to it's content size…
Msencenb
  • 5,675
  • 11
  • 52
  • 84
67
votes
7 answers

Layout attributes relative to the layout margin on iOS versions prior to 8.0

What would be causing the following warning (and subsequent alignment issues on iOS 7)? Attribute Unavailable: Layout attributes relative to the layout margin on iOS versions prior to 8.0
Andy
  • 14,260
  • 4
  • 43
  • 56
65
votes
5 answers

UITableViewCell with autolayout left margin different on iPhone and iPad

I am using a grouped UITableView with static cells for an options screen/scene. Everything is done in Xcode 6.1 / iOS 8.1.x / Storyboard using Autolayout. Within the table groups there are mixed types of cells and there are two types that cause me…
The Lone Coder
  • 3,062
  • 4
  • 20
  • 35
65
votes
5 answers

iOS 8 UIPageViewController Applying Constraints After Transitions

My app has a multi-pane tutorial-style view that users swipe through to learn about the app. This is implemented very much as described in this tutorial. Having implemented it for both iOS 7 and 8, I'm comparing how they work, and finding issues…
Aaron Vegh
  • 5,217
  • 7
  • 48
  • 75