Questions tagged [ios-autolayout]

In iOS, Auto Layout dynamically calculates the size and position of all the views in your view hierarchy, based on constraints placed on those views.

In iOS, Auto Layout dynamically calculates the size and position of all the views in your view hierarchy, based on constraints placed on those views.

More info

1049 questions
306
votes
23 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
  • 17,070
  • 9
  • 50
  • 73
132
votes
30 answers

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 for the first few cells that height isn't properly…
blackp
  • 1,752
  • 3
  • 13
  • 14
125
votes
18 answers

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 to use: override func layoutSubviews() { …
charbinary
  • 1,875
  • 4
  • 17
  • 25
91
votes
3 answers

What is 'Vary for Traits' in Xcode 8?

I am using AutoLayout and Size classes, but with release of iOS 10 and new Xcode 8.0, there is one new option Vary for Traits. Is this replacement of Size Classe for different width and height of devices. By selection of width checkbox, it…
technerd
  • 14,144
  • 10
  • 61
  • 92
90
votes
6 answers

How can I create UIStackView with variable spacing between views?

I have a simple horizontal UIStackView with several UIViews stacked inside. My goal is to create variable spacing between views. I am well aware that I can create constant space between the subviews using "spacing" property. However my goal is to…
yura
  • 1,474
  • 1
  • 12
  • 16
89
votes
12 answers

Swift default AlertViewController breaking constraints

I am trying to use a default AlertViewController with style .actionSheet. For some reason, the alert causes a constraint error. As long as the alertController is not triggered (displayed) through a button, there are no constraint errors on the whole…
linus_hologram
  • 1,595
  • 13
  • 38
75
votes
9 answers

How to fix "Scrollable Content Size Ambiguity" in Xcode 11 (iOS 12, iOS 13) using Auto Layout

When using Auto Layout, I am unable to set up a simple UIScrollView in my view controller in Xcode 11 beta. I know that I must constrain the scroll view to the edges, and then set the scroll view width and height equal to the width and height of the…
Pranav Ramesh
  • 780
  • 1
  • 5
  • 9
57
votes
10 answers

How to remove constraints programmatically that is added from storyboard?

I have googled but not find out answer. So I need to ask. I have one home screen. When User is logged in it will display one view as like bellow Now When User logged out and visiting home page he will see above layout but without center boxed…
Dharmik
  • 2,325
  • 3
  • 27
  • 37
53
votes
8 answers

In iOS 12, when does the UICollectionView layout cells, use autolayout in nib

Same code like this collectionLayout.estimatedItemSize = CGSize(width: 50, height: 25) collectionLayout.itemSize = UICollectionViewFlowLayoutAutomaticSize collectionLayout.minimumInteritemSpacing = 10 for _ in 0 ..< 1000 { let length =…
EvilHydra
  • 552
  • 1
  • 5
  • 9
50
votes
3 answers

Why weak IBOutlet NSLayoutConstraint turns to nil when I make it inactive?

I have an IBOutlet NSLayoutConstraint in my app. Very simple: @property (nonatomic, weak) IBOutlet NSLayoutConstraint* leftConstraint; At some point I want to deactivate this constraint: self.leftConstraint.active = NO; It happens in a method…
Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
50
votes
15 answers

How to keep a round imageView round using auto layout?

How do I turn a rectangular image view into a circular image view that can hold shape in auto layout without setting width and height restraints? Thereby allowing the imageView to define it’s size, and size bigger and smaller relative to objects…
CHM
  • 621
  • 1
  • 5
  • 7
43
votes
2 answers

Swift dynamic table cell height

I have tableview with prototype cell, in the cell I have imageview and some text under. The text label is one laine in the prototype cell, but sometimes it is more than one line, I'm loading the data to the table view after server call. The label…
SpyZip
  • 5,511
  • 4
  • 32
  • 53
41
votes
8 answers

How to get real size UIView with autolayout

I'm a new developer iOS. I use auto-layout. I have a problem. I can not get real size of UIView after constraints. Example, when I want get size of UIView with constraint self.container.frame.size.height It alway return 550 for all device size. But…
Chicken
  • 447
  • 1
  • 4
  • 8
36
votes
6 answers

UIHostingController should expand to fit contents

I have a custom UIViewControllerRepresentable (layout-related code shown below). This tries to replicate the native SwiftUI ScrollView, except it scrolls from the bottom except the top. View hierarchy view: UIView | \- scrollView: UIScrollView | …
Potassium Ion
  • 2,075
  • 1
  • 22
  • 39
36
votes
4 answers

Dividing screen in to 1/3 and 2/3 views using autolayout

Is there a way to divide the screen by percentage (not equal percentage) I need to split the screen to two parts 1/3 and 2/3. I know how to split to equal parts but cant figure out how to split to non equal. Thanks
ilan
  • 4,402
  • 6
  • 40
  • 76
1
2 3
69 70