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

Why NSLayoutConstraint is optional type?

Usually I avoid to ask a new question here on stackoverflow, because 90% of questions easily solved by searching. But sometimes you can't do in this way. I have several objects class GameTimer : UIView that I add to the array var timersArray:…
Andrew V. Jackson
  • 273
  • 1
  • 4
  • 14
0
votes
1 answer

Updating Constraints in UITableViewCell are not properly

I want to make a dynamic cell in my UITableView in case of image height. Everything works properly, but when I scroll my UITableView, debugger is yelling me about bad constraints in my cell, but cells look exactly what I want. I can't be calm when I…
PiterPan
  • 1,760
  • 2
  • 22
  • 43
0
votes
0 answers

iCarousel "cards" disappear when NSLayoutConstraint is applied

I am currently working with iCarousel https://github.com/nicklockwood/iCarousel on my project. The objective is to come up with a spotify cover flow UI. I am facing problems with the following code: func carousel(_ carousel: iCarousel,…
curiousDog
  • 83
  • 1
  • 8
0
votes
0 answers

Is it possible to create NSLayoutConstraint where value is not constant but related to property?

Constraints in iOS has base related element, constant (and also multiplier, priority and other properties, but they are not matter in this question): view.leftAnchor.constraint(equalTo: superView.leftAnchor, constant: 0).isActive = true Can I…
General Failure
  • 2,421
  • 4
  • 23
  • 49
0
votes
2 answers

How can I set max width and height on UIImageView while maintaining 1:1 ratio?

I am trying to do this in storyboard but can't seem to figure it out. I have a QR code (square UIImageView) centered (vertically and horizontally) in another UIView that I want to expand a bit depending on phone size, but I don't want it to go over…
Jason Fel
  • 921
  • 4
  • 10
  • 29
0
votes
2 answers

Call function for one UICollectionViewCell only

I have got custom UICollectionViewCell and here is cellForItemAt: method: func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell =…
sakoaskoaso
  • 347
  • 4
  • 17
0
votes
3 answers

How to update constraints dynamically?

I have three UIButton, I have created programmatically constraints, at some condition i am removing one of UIButton as button.removeFromSuperview() & rest of two button will set constraints as per priorities. Issue is when i am removing one…
Jack
  • 13,571
  • 6
  • 76
  • 98
0
votes
2 answers

Child view is never visible

I'm building our UI programmatically and am having a bit of trouble getting elements to render for children views. I am setting up the apps Window by instantiating my initial view controller and the view that it needs. class AppDelegate:…
Johnathon Sullinger
  • 7,097
  • 5
  • 37
  • 102
0
votes
1 answer

thread 1:signal sigabrt error constraints withVisualFormat

i am designing my video app , and i dont use main.storyboard for design and only use codes in viewcontroller.swift in xcode 8 swift 3 my problem is after i add lines below to viewcontroller.swift…
Babak
  • 19
  • 4
0
votes
3 answers

How to Increase/decrease UIButton width according to title lable text changes?

The Question I have asked is purely using auto-layout, I don't want to setup the frames manually according to text width. I am aware of the changes Content hugging priority and I have used the same for one label and one button it works fine for the…
Satish Mavani
  • 4,897
  • 2
  • 20
  • 30
0
votes
1 answer

NSLayoutConstraint activate/deactivate

I am simply trying to deactivate a constraint in textViewDidBeginEditing and the deactivate in textViewDidEndEditing. My NSLayoutConstraint is an outlet. The deactivation in textViewDidBeginEditing works, but then the reactivation on…
daredevil1234
  • 1,303
  • 1
  • 10
  • 34
0
votes
1 answer

Swift3 - Visual Format Constraint crashing

Im trying to add constraints to a UICollectionViewCell with the visual format in the setupViews() function but whenever I set them and then run the code the constraints crash and no cells are displayed. I get the Error of: [LayoutConstraints] Unable…
0
votes
2 answers

Arrange horizontal space between items in a bar using autolayout

I'm currently has a View like this, how can I setup the constraint to display the items equally like the Iphone 7 review in all size of screen?. I've tried so many constraint including stackView but no use. Thank you very much and have good day…
0
votes
1 answer

Cell subviews constraints changing programmatically in CellForRowAtIndex

I have a UITableViewcustom cell. It has a UIViewand a UIButton I want to change this view height constraint and the button's top constraint programmatically in my `cellForRowAtIndex. So Inside this im doing like this. if(myintime2 == "00:00" &&…
user1960169
  • 3,533
  • 12
  • 39
  • 61
0
votes
4 answers

Autolayout not working on centerX- centerY

I am trying to add constraint manually; I am having the following error every time the code tries to add the centerX and centerY constraints: Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on…
Tarek A.
  • 218
  • 2
  • 12