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

What is it called when you bind a method and variable of a class in swift?

I'm following a book's tutorial on programmatic constraints and decided to read Apple's programming guide afterwards. I saw the following line of code in Apple's guide which is using a method and a variable in one line of code: // Pin the leading…
Laurence Wingo
  • 3,912
  • 7
  • 33
  • 61
0
votes
1 answer

Does autolayout add width constraints that I can't remove?

Whenever I write for iOS, I always struggle with Autolayout. Does anyone else have these problems? How do you overcome it? Have you reverted to alternatives like SnapKit? This is what I'm trying to accomplish: UITableViewCell …
0
votes
1 answer

Swift4 issues : change Nslayoutconstraint programmatically

I would like to change position of UITextfield txtAmount NSLayoutConstraint programmatically from its top to bottom of collection view to bottom of image view. All views are embed in a ui view. Old constraint is dragged and mapped from storyboard…
Jeff Bootsholz
  • 2,971
  • 15
  • 70
  • 141
0
votes
1 answer

How to add width constrain using constraintsWithVisualFormat while already using constraintsWithVisualFormat for vertical spacing between two view?

I am new to IOS and I am adding constrain to my added view with using constraintsWithVisualFormat. I already use constraintsWithVisualFormat to have vertical spacing by these following code:- self.underlineConstraints = [NSLayoutConstraint …
shree Ram
  • 5
  • 1
  • 8
0
votes
1 answer

Constraints animation is incorrect

I created uiview custom class and implemented in Main View Controller -(KPHomeChartCategory *)chartCategory { if (!_chartCategory) { _chartCategory = [[KPHomeChartCategory alloc] init]; _chartCategory.delegate = self; …
kAiN
  • 2,559
  • 1
  • 26
  • 54
0
votes
1 answer

Increasing height constraint, stretching "Runtime added subviews"

The line mentioned with *comments is stretching the subviews that are not bound with any constraint to its parent view. NSMutableArray* tagItemLabels=[NSMutableArray new]; NSMutableArray* data = [NSMutableArray arrayWithObjects:@"One",@"One…
Muhammad Sarim
  • 401
  • 5
  • 11
0
votes
1 answer

Adding table to navigation controller view programatically doesnt work

When attempting to add a table to cover the entire view of a view controller like so: func setConstraints(){ self.view.addSubview(statisticsTable); statisticsTable.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true; …
Return-1
  • 2,329
  • 3
  • 21
  • 56
0
votes
3 answers

Constraints in Swift not working

I'm trying to add some constraints to my view, but everytime I switch the device, the view goes crazy. How can I fix this? How I want it to look and how it looks like on the iPhone 8 Plus: How it looks like when I switch to iPhone SE: I added…
0
votes
1 answer

constraint LefAnchor constant not updating

I'm trying to update the constant value of the leftAnchor. But it's not working as I hoped it would, it's not updating anything. var horizontalBarLeftAnchorConstraint: NSLayoutConstraint? func setupHorizontalBar () { let horizontalBarView =…
0
votes
1 answer

How to make UILabel and UITextField font size to be relative to screen size

I have a view controller which has a text field and label and I have set height constraint for text field and label and so I feel font size is not relative to the screen I believe. How can I make this items' font size to be relative to the screen…
Dan Ram
  • 171
  • 1
  • 14
0
votes
1 answer

How to create a table whose height can be autoadjusted

I have a tableview whose height is 70% of the screen sometimes I don't have enough rows to fill up all 70% then in that case there are some empty spaces with blank rows and it looks awkward.so if the height gets auto adjusted to the tablerows…
Elstine P
  • 340
  • 4
  • 22
0
votes
0 answers

Is it possible to get part of tableview cell to disappear by reducing it height at tableview delegates

I have a table view cell which has three elements vertically a title label a text box a validation label I want to show validation label only when it fails. If I just hide the validation label then the space occupied by the label is stil there…
Shankar Naik
  • 401
  • 5
  • 16
0
votes
1 answer

Using NSLayoutAnchor to create constraints between two labels?

I'm creating a view programmatically and need to set constraints between two labels. I recently just discovered NSLayoutAnchor and feel it would be a good choice to use it but I'm unsure how to create constraints between two different things (ie…
SwiftyJD
  • 5,257
  • 7
  • 41
  • 92
0
votes
2 answers

iOS11 not taking constraints correctly

I have an app on the store, in order to support all devices and keyboard I am changing the bottom constraint height according to keyboard height. It is working on all iOS versions except on iOS11. The button is not changing its place as it is shown…
Tarek A.
  • 218
  • 2
  • 12
0
votes
2 answers

Text won't show with constraints added

So here is my current code for the viewdidload and the setup view func override func viewDidLoad() { super.viewDidLoad() view.addSubview(bearImageView) view.addSubview(descriptionText) …
Dengekiko
  • 63
  • 1
  • 1
  • 4