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

Label show out of my range of Customized TableViewCell and set auto-layout by swift

I use xib to creat a chat bubble tableViewCell, but I use auto layout to set the constrains. It show my text out of range which I input. And I also don't want to shrink the text. And I also add textLabel left constrain, It makes different type…
0
votes
2 answers

Auto layout constraints not working properly swift 3.0

Kinda new to this whole auto layout constraints part. My app is closing up on a beta and i'm having trouble getting the constraints right. In the picture below i have succesfully managed to add the following constraints to each object Horizontally…
Ulrik. S
  • 326
  • 2
  • 14
0
votes
1 answer

Aspect ratio constraint relative to the screen width

I have set a cell image to my UITableViewCell. It is a custom cell. I have set the aspect ratio as 1:1 and the width of the image view to 50. But for iphone 5 and 5s this size is too big as I feel. So how can I change the size of the UIImageView…
user1960169
  • 3,533
  • 12
  • 39
  • 61
0
votes
1 answer

How to AddConstraint to a button relative to parent view's margin so that it appears 30 from top margin and 30 from right margin

This is the code I'm trying out: @IBOutlet weak var btnInfo: UIButton! override func viewWillAppear(_ animated: Bool) { self.view.addConstraint(NSLayoutConstraint(item: self.view, attribute:…
as diu
  • 1,010
  • 15
  • 31
0
votes
2 answers

I need top constraint of unknow element

I have an app which is downloading image from server by clicking the button. After image have downloaded i create a new imageView and add it to the my contentView(UIView). I need to create the constraints - every new imageview need top constraint…
sergs
  • 109
  • 1
  • 9
0
votes
1 answer

Align equal UIViews on the bottom with fixed height

I've been trying to achieve something like the example below for quite a while now without success. Here's what I have so far: H:|[firstView][secondView(== firstView)][thirdView(== firstView)][fourthView(== firstView)]| Which works, but, it yields…
COOKIES
  • 434
  • 4
  • 14
0
votes
1 answer

Swift: Change centre constraint based on visible frame

I've been trying to vertically centre a UILabel across all devices, both when the keyboard isn't visible and when it is visible. I previously tried to adjust the top constraint by doing this: self.emptyStateMessageTopConstraint.constant =…
daanyyaal
  • 301
  • 2
  • 4
  • 16
0
votes
1 answer

Nil not compatible with expected argument type 'NSLayoutAnchor'

this is the problematic code // auto layout let vertivalConstraint = textField.centerYAnchor.constraint(equalTo: self.codeView.centerYAnchor) let leadingConstraint = textField.leadingAnchor.constraint(equalTo:…
Johny D Good
  • 427
  • 1
  • 8
  • 26
0
votes
1 answer

UIView disappearing after adjusting constraint and animating

I have a UITextField (searchField) at the center of my viewcontroller and I'm creating a thin line by using UIView (liveView). I create the lineView and its constraints programmatically. The lineView is essentially an underline that grows in width…
Brosef
  • 2,945
  • 6
  • 34
  • 69
0
votes
0 answers

NSLayoutconstraint created programmatically fails

I am on Xcode 8.3.3, OSX not iOS. I have a customView I use as container to replace other views inside it. The dark blue box on the right represents the container: The constraints of the container are set in IB as follows where "scrollView" is the…
Pat_Morita
  • 3,355
  • 3
  • 25
  • 36
0
votes
1 answer

How to remove a view and update constraints?

I have a view in which i am creating another view programmatically on add button through xib. I am able to create multiple views on tapping add more button and remove is also working if I remove last view but the problem occurs with middle views due…
Varun Naharia
  • 5,318
  • 10
  • 50
  • 84
0
votes
2 answers

UITextView auto layout height when using exclusion path

I have a UITableViewCell containing a UITextView and a UIImageView. The text view has scrolling disabled. The UITableViewCell does use auto layout to calculate its height to fit the content. If there is more text than in the screenshot I want the…
0
votes
4 answers

iOS - Change vertical spacing between 2 UIView

I have 3 different scenarios for a single XIB File. Here is the XIB File, I have 3 different UIView. My scenarios are : View 2 is displayed and View 1 and View 3 are hidden. View 1 and View 3 are displayed and View 2 is hidden. View 1, View 2 and…
user7219266
0
votes
0 answers

Is there a better way to evenly distribute subviews in a UIview with unknown size?

I want to horizontally place 4 subviews in a screen-width view, and I want the subviews to be evenly distributed (with equal horizontal spacing). One way to do it is to use hidden placer-views, and add equal-width constraints: Evenly space multiple…
NeoWang
  • 17,361
  • 24
  • 78
  • 126
0
votes
1 answer

Aspect ratio constraint not getting altered

I have two kinds of image 1.Square and other 2. Images with ratio 3:4. And I get information about the aspect ratio of incoming image in advance(which is in currentImageAspectRatio). I want to handle both kind of images in one UIImageView. In…
Nikhil Manapure
  • 3,748
  • 2
  • 30
  • 55
1 2 3
99
100