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
90
votes
3 answers

iOS autolayout to center my view between two views

How to set up autolayout in Interface Builder to arrange views vertically as shown on image: Top view pinned to top screen edge, Bottom view pinned to bottom screen edge. My view should be centered between top and bottom views (so distance to Top…
brigadir
  • 6,874
  • 6
  • 46
  • 81
88
votes
12 answers

How do I set the height of tableHeaderView (UITableView) with autolayout?

I'm been smashing my head against the wall with this for last 3 or 4 hours and I can't seem to figure it out. I have a UIViewController with a full screen UITableView inside of it (there's some other stuff on the screen, which is why I can't use a…
Andrew Cross
  • 1,921
  • 2
  • 19
  • 32
86
votes
11 answers

Width and Height Equal to its superView using autolayout programmatically?

I've been looking for a lot of snippets in the net and I still can't find the answer to my problem. My question is I have a scrollView(SV) and I want to add a button inside scrollView(SV) programmatically with same width and height of its superview…
Bordz
  • 2,810
  • 4
  • 23
  • 27
84
votes
4 answers

resize superview after subviews change dynamically using autolayout

I cant for the love of god the the hang of this resizing superview. I have a UIView *superview with 4 UILabels. 2 function as header for the 2 others. The content in all 4 are dynamic coming from database. SizeToFit vs SizeThatFits:(CGSize) vs…
Pedroinpeace
  • 1,419
  • 1
  • 14
  • 20
84
votes
6 answers

Creating layout constraints programmatically

I know that a lot people already asked tons of questions about this, but even with the answers I can't make it work. When I'm dealing with constraints on storyboard, it's easy but in code I have a hard time. I try, for example, to have a view that…
pierre23
  • 3,846
  • 1
  • 28
  • 28
83
votes
7 answers

Reuse a uiview xib in storyboard

I typically like to create and design my uiviews in interface builder. Sometimes I need to create a single view in a xib that can be reused in multiple view controllers in a storyboard.
Garfbargle
  • 3,222
  • 2
  • 17
  • 17
83
votes
8 answers

Auto Layout constraint on CALayer IOS

Hi I am developing iPhone application in which I tried to set one side border for edittext. I did this in following way: int borderWidth = 1; CALayer *leftBorder = [CALayer layer]; leftBorder.borderColor = [UIColor…
nilkash
  • 7,408
  • 32
  • 99
  • 176
83
votes
8 answers

Centering subview's X in autolayout throws "not prepared for the constraint"

I have a custom UIView subclass which is being initialized via a nib. In -awakeFromNib, I'm creating a subview and attempting to center it in its superview. [self setInteralView: [[UIView alloc] init]]; [[self internalView] addConstraint:…
81
votes
9 answers

Where should I be setting autolayout constraints when creating views programmatically

I see different examples where constraints are set. Some set them in viewDidLoad / loadView (after the subview was added). Others set them in the method updateViewConstraints, which gets called by viewDidAppear. When I try setting constraints in…
Heisenberg
  • 1,319
  • 1
  • 12
  • 15
80
votes
13 answers

iOS equivalent for Android View.GONE visibility mode

I'm developing an app for iOS and I'm using the Storyboard with AutoLayout ON. One of my view controllers has a set of 4 buttons, and in certain circumstances i would like to make the first one disappear. If I use the setHidden:TRUE method the…
elbuild
  • 4,869
  • 4
  • 24
  • 31
79
votes
1 answer

Proportional height (or width) in SwiftUI

I started exploring SwiftUI and I can't find a way to get a simple thing: I'd like a View to have proportional height (basically a percentage of its parent's height). Let's say I have 3 views vertically stacked. I want: The first to be 43% (of its…
superpuccio
  • 11,674
  • 8
  • 65
  • 93
79
votes
4 answers

UIScrollView doesn't use autolayout constraints

I have a scroll view and an image view behind it and I am populating it with nibs. I am using autolayout. I have a bottom space to superview and a top space to superview on both of the views. The image view does exactly what I want it to do. For…
SirRupertIII
  • 12,324
  • 20
  • 72
  • 121
78
votes
5 answers

Sizing a Container View with a controller of dynamic size inside a scrollview

I'm trying to create a container view, with a controller that has a dynamic height, inside a UIScrollView and have it sized automatically using auto layout. View Controller A is the scrollview, which has the container view included, along with more…
78
votes
15 answers

Auto-layout: What creates constraints named UIView-Encapsulated-Layout-Width & Height?

My layout constraints are fine in Interface Builder but an exception occurs at runtime thanks to some part of the framework applying fixed height and width constraints that I really don't want. Why are they there, and how to turn them off? They're…
Reuben Scratton
  • 38,595
  • 9
  • 77
  • 86
77
votes
8 answers

Xcode 11 add new constraints set zero: use set value instead of default / standard

I used to use autolayout add new constraints to make simple constraints to superview / relative view like this (for loooong time): However, recently after updated to the latest xcode (11.3.3 or just 11.3/11C29), I have this weird issue: when I set…
Eddie
  • 1,903
  • 2
  • 21
  • 46