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
115
votes
31 answers

"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 me a lot of trouble. I setup my table view and…
Mike Mayo
  • 1,259
  • 2
  • 9
  • 5
114
votes
7 answers

Autolayout: Add constraint to superview and not Top Layout Guide?

I have a UIView in my UIViewController in storyboard which I want to add a constraint on to space that view a distance from the top edge. Now, when I do the usual by ctrl + drag to the ViewController's main view I only get option to set it to top…
Arbitur
  • 38,684
  • 22
  • 91
  • 128
114
votes
29 answers

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

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 I added this CustomView to the…
ItsASecret
  • 2,589
  • 3
  • 19
  • 32
110
votes
14 answers

Can I disable autolayout for a specific subview at runtime?

I have a view that needs to have its frame manipulated programmatically - it's a kind of document view that wraps to its content which is then scrolled and zoomed around a superview by manipulating the frame origin. Autolayout fights with this at…
terriblememory
  • 1,712
  • 3
  • 18
  • 25
109
votes
5 answers

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 don't want. Try this: (1) look at each constraint…
Markus Rautopuro
  • 7,997
  • 6
  • 47
  • 60
108
votes
7 answers

Programmatically Add CenterX/CenterY Constraints

I have a UITableViewController that doesn't display any sections if there is nothing to show. I've added a label to indicate to the user that there is nothing to display with this code: label = UILabel(frame: CGRectMake(20, 20, 250,…
Mario A Guzman
  • 3,483
  • 4
  • 27
  • 36
108
votes
16 answers

Remove all constraints affecting a UIView

I have a UIView which is placed on the screen via several constraints. Some of the constraints are owned by the superview, others are owned by other ancestors (e.g. perhaps the view property of a UIViewController). I want to remove all of these old…
Senseful
  • 86,719
  • 67
  • 308
  • 465
106
votes
10 answers

Auto layout constraints issue on iOS7 in UITableViewCell

I'm using auto layout constraints programmatically to layout my custom UITableView cells and I'm correctly defining the cell sizes in tableView:heightForRowAtIndexPath: It's working just fine on iOS6 and it does look fine in iOS7 as well BUT when I…
Alexis
  • 16,629
  • 17
  • 62
  • 107
104
votes
7 answers

How can I set aspect ratio constraints programmatically in iOS?

I have used auto layout for my view controllers. I have set the V and H positions in constraints, but I want to know how can I increase my button size when it changes to 5s, 6 and 6 Plus. This is the way I added constraints for the login…
IRD
  • 1,127
  • 2
  • 8
  • 15
102
votes
16 answers

Layout issues after updating to Xcode 8

Here is a before and after of one of my screens after I upgraded to Xcode 8.All I did was open up my main.storyboard and from there, I built and ran my app on my phone.In my version control, I can see Xcode is doing a lot of changes to my…
user2726072
  • 1,031
  • 2
  • 8
  • 4
102
votes
14 answers

UIStackView "Unable to simultaneously satisfy constraints" on "squished" hidden views

When my UIStackView "rows" are squished, they throw AutoLayout warnings. However, they display fine and nothing else is wrong besides these sorts of loggings: Unable to simultaneously satisfy constraints. Probably at least one of the…
Ben Guild
  • 4,881
  • 7
  • 34
  • 60
98
votes
8 answers

How can I change constraints priority in run time

I have a view which has dynamic height and I am trying to change this view height priority in run time. Here is my part of code; if (index == 0) { surveyViewHeightConstraint.constant = 0; surveyViewHeightConstraint.priority = 1000; } else…
Kirdok
  • 1,904
  • 2
  • 22
  • 27
98
votes
5 answers

iOS Autolayout: two buttons of equal width, side by side

I am currently having difficulty with AutoLayout. I am using interface builder and am trying to position two buttons of equal width side by side as illustrated in the following image. From the following Preview image, my titleImage has been…
Scratcha
  • 1,359
  • 1
  • 14
  • 22
96
votes
3 answers

"Width equals height" constraint in Interface Builder

I can't find a way to create a 'square' constraint, meaning 'width equals height' in Interface Builder. I guess it's possible to add such constraint programmatically. Is there something I can do in IB? Maybe I just don't see it? It seems trivial,…
DemoniacDeath
  • 1,778
  • 3
  • 13
  • 25
95
votes
13 answers

Since Xcode 8 and iOS10, views are not sized properly on viewDidLayoutSubviews

It seems that with Xcode 8, on viewDidLoad, all viewcontroller subviews have the same size of 1000x1000. Strange thing, but okay, viewDidLoad has never been the better place to correctly size the views. But viewDidLayoutSubviews is! And on my…
Martin
  • 11,881
  • 6
  • 64
  • 110