Questions tagged [nslayoutconstraint]

NSLayoutConstraint is a constraint defines a relationship between two of user interface objects that must be satisfied by the constraint-based layout system. Available in iOS 6.0 and later in UIKit and available in OS X v10.7 and later in AppKit.

A constraint defines a relationship between two attributes of user interface objects that must be satisfied by the constraint-based layout system.

The relationship involves a first attribute, a relationship type, and a modified second value formed by multiplying an attribute by a constant factor and then adding another constant factor to it. In other words, constraints look very much like linear equations of the following form:

attribute1 == multipler × attribute2 + constant

The right side of this equation can be considered a modified attribute, so this equation could be described in words as “attribute one must be equal to the modified attribute two.” Note that the constraint-based layout system is free to modify the attributes on either side of the equation as part of satisfying the system of constraints that apply to the objects being laid out.

Constraints are not limited to equality relationships. They can also use greater than or equal (>=) or less than or equal (<=) to describe the relationship between the two attributes. Constraints also have priorities, indicating to the layout system which constraint should take priority when two or more constraints are in conflict. The combination of a set of constraints, along with the set of priorities for applying those constraints, can uniquely describe the relationship between multiple user interface elements in all legal configurations for those elements, allowing the system to dynamically layout the user interface as the size and location of user interface elements change.

Source: Apple IOS Developer Library (NSLayoutConstraint class reference)

2151 questions
0
votes
1 answer

iOS Autolayout - constraints modifications lost on orientation change?

If I modify my constraints (lets say activate some and deactivate others) and then rotate to a different orientation my interface snaps back to the original unmodified state. How do I preserve this changes?
georgij
  • 2,054
  • 4
  • 27
  • 43
0
votes
0 answers

How am I suggesting a TableViewCell height of zero?

I have a tableView with some static cells. It's set to automatically calculate the row height. The bottom most button is in a cell with a height constraint along with top, bottom, leading, and trailing. All constraints are done in the interface…
Aaron Bratcher
  • 6,051
  • 2
  • 39
  • 70
0
votes
1 answer

UITableViewCell change label constraints when increasing font size

I want to change label top and bottom constraint in cell when increasing font size: @IBAction func changeFontSize(_ sender: UIBarButtonItem) { fontSize += 2 self.tableView.reloadData() self.tableView.reloadInputViews() …
Almudhafar
  • 887
  • 1
  • 12
  • 26
0
votes
1 answer

Autolayout proptional constrain not working properly iOS

I have one bug in which proportional constrain not working properly My image view size is 220 * 176 in 5S devices I want height and width proportionally in bigger devices Image size will be 1280 * 1024 which is coming from backend, i tried but in…
0
votes
0 answers

programmatically generate UITableviewCell with constraints which has dynamic heights

My iOS app has several UIViewControllers which include UITableViews. I have a single class called ListScreenManager and according to the passing data this class generates the cells for various UITableViews. This is one of table delegate…
0
votes
1 answer

Constrains causing black spots on display

I am pretty new to styling/Constraints/Auto-Layout in iOS. I am having a problem that when I apply constrains to one of my ViewControllers I get black "bars" around the edges. Here is what it looks like in the story board: Here is what it looks…
zoecarver
  • 5,523
  • 2
  • 26
  • 56
0
votes
2 answers

How do I update a constraint from the Storyboard without an IBOutlet or Identifier?

I have a lot of views that are created in the storyboard, but I want them to be able to update their constraints dynamically without having to use an IBOutlet each time. I started by making a custom class for the superview of the view I want to…
caziz
  • 23
  • 1
  • 7
0
votes
1 answer

NSLayoutConstraint for UITableViewCell: Constraint must contain a first layout item

I am trying to set NSLayoutConstraint within each of my custom cells (inherited from UITableViewCell), rather than specifying them in a UIViewController to avoid cluttering it by exposing the constraints for each cell type. The problem is that I…
Peter G.
  • 7,816
  • 20
  • 80
  • 154
0
votes
1 answer

UIButton height not being set correctly on UITableView

I have an UITableView which holds a list of items. For each UITableViewcell in that table, depending on a property from the associated object to that cell, I toggle the visibility of an UIButton by changing the height constraint constant to 0, or to…
auhmaan
  • 726
  • 1
  • 8
  • 28
0
votes
1 answer

Equal width constraint + center horizontally constraint not working

I just find a strange behavior in Interface Builder with Storyboard. If I set a UIView with: • Equal Width to the superview, multiplier 1 • Center horizontally to the superview, multiplier x Then I would expect the width always as the same value but…
Dam
  • 579
  • 6
  • 22
0
votes
1 answer

Add NSLayoutConstraint for a view inside a UITableCellView

I would like to have a UIButton centred inside my UITableCellView. I've added the necessary code in the tableView cellForRowAt function but I get the error : The view hierarchy is not prepared for the constraint: When added to a view, the…
113408
  • 3,364
  • 6
  • 27
  • 54
0
votes
2 answers

Understanding visual format constraints in iOS Objective C

I know about setting constraint in InterfaceBuilder ex. Leading, trailing, top, bottom, fixed width etc.. I found some constraint code, I don't know what this code trying to set which constraint, What is exactly meaning of below visual format…
Akshay
  • 153
  • 3
  • 13
0
votes
0 answers

Custom UITableViewCell: keep aspect ratio when height is set using NSLayoutConstraint

I have a custom UITableViewCell where I want to display an image with a height I've set. As it is a custom cell, I want the image to be modified by the UITable that uses this custom cell (from cellForRowAt override). In this case, I want to fix the…
Anthony
  • 804
  • 3
  • 12
  • 32
0
votes
3 answers

Placing UiView as a subview programmatically

I have ViewController that looks like this. There is parent ScrollView that holds UIView (wrapperView) and this wrapper view has TextView and ImageView inside. This simple structure is created form interface builder with all constraints needed so it…
moonvader
  • 19,761
  • 18
  • 67
  • 116
0
votes
0 answers

Xcode ViewController elements is not interactive after animation

I have a project that need to have a top sheet, that when user scrolling down it will reveal. so I created 2 separate ViewController in storyboard like this: in the main ViewController I add the sheet view controller as a subview like this: let…