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

How to concatenate UIButton along with UIText

I want to add a UIButton at the end of a sentence in UIView. Presently I have a UILabel to display text and a button next to it. Both are subviews to UIView. I get the desired o/p if the sentence spans to 2 lines. How should I modify it, for it to…
gowtham
  • 73
  • 1
  • 11
0
votes
0 answers

how to remove button with equalwidths dynamically

I have three buttons with equal widths in storyboard , now i want to remove one button dynamically , so that other two should fit equally
Venkat Reddy
  • 111
  • 1
  • 8
0
votes
2 answers

iOS leftSpacingConstraint relative to screen height

I am working on an older iOS project, written mostly in Objective C. I have these line in the code (to set an object to the middle of the screen): self.leftSpacingConstraint.constant = 250.0; self.rightSpacingConstraint.constant = 250.0; I would…
Gefilte Fish
  • 1,600
  • 1
  • 18
  • 17
0
votes
1 answer

How do I automate the position of a UIViewController container's member view?

Scenario: 1. UIViewContainer having one (1) child UIViewController. 2. I'm using a UIStoryboard. Goal: To animate the entrance of the child UIViewController's view from the left edge of the container (like a UIActionSheet). I have initially set…
Frederick C. Lee
  • 9,019
  • 17
  • 64
  • 105
0
votes
0 answers

Xamarin iOS: The constraints adjust differently on different devices

I'm using storyboard to set the constraints for the view. For a view, I set the constraints along the edges of the screen. So the view edge == edge of the screen . This works well for iPhone, 6s,7,7+ but the constraints are off on smaller devices…
TheDeveloper
  • 1,127
  • 1
  • 18
  • 55
0
votes
1 answer

NSLayoutConstraints not working in reference to view

I want to create a container view based on the view size. The code speaks for itself but it doesn't work. I've tried using override viewWillAppear to no avail. import UIKit class ViewController: UICollectionViewController,…
Stefan
  • 908
  • 1
  • 11
  • 33
0
votes
1 answer

centerXAnchor is only available in iOS 9.0 or newer?

So I'm trying to add constraints programmatically: I'm simply adding two constraints and Xcode has started to show me: centerXAnchor is only available in iOS 9.0 or newer Here is my code: var constraints = [NSLayoutConstraint]() let centerImageX…
Yash Bedi
  • 1,323
  • 17
  • 25
0
votes
0 answers

What's the real meaning of `AmbiguousLayout` in AutoLayout

Here is my test code written with Masonry, VFL and NSLayoutConstrant methods: UIView *view1 = [UIView generateView]; UIView *view2 = [UIView generateView]; UIView *view3 = [UIView generateView]; [self.view addSubview:view1]; [self.view…
0
votes
1 answer

Programatic Constraints Not Obeyed

I run the below code on a button press, however the bottom constraint does not seem to be obeyed. The subview (bandCardView) overflows the bottom of the parent view (formVw). How can I make these constraints obeyed? @objc private func…
steventnorris
  • 5,656
  • 23
  • 93
  • 174
0
votes
1 answer

How to get an NSLayoutAnchor from a switch case?

I'd like to do something like: public enum LayoutEdge { case top case right ... } func anchorForLayoutEdge(_ edge : LayoutEdge) -> NSLayoutAnchor { switch edge { case .top: return topAnchor case .right: return…
GoldenJoe
  • 7,874
  • 7
  • 53
  • 92
0
votes
1 answer

iOS 10 square UIIMageView in Stackview breaks Autolayout when hidden

I have a UITableViewCell with something I thought was a pretty straight forward layout. The main content is a UIStackView (horizontal). In it I have UIImageView and two UILabels. On the UIImageView I have 2 constraints. One is an aspect ratio of 1:1…
xxtesaxx
  • 6,175
  • 2
  • 31
  • 50
0
votes
0 answers

UITableView cell change anchor constraint in cellForRowAt

In my table view cell I have var myAnchor: NSLayoutConstraint? let myAnchor = myView.widthAnchor.constraint(equalToConstant: screenWidth / 6).isActive = true Then in my table view cellForRowAt function I have if indexPath.row == myArray.count…
markhorrocks
  • 1,199
  • 19
  • 82
  • 151
0
votes
1 answer

How to make subviews resize to UIScrollView ContentSize?

I have a UIViewController that acts as a Container View Controller. It has a UIScrollView that has the same width as the screen, but it's height is smaller than the height of the screen. The UIScrollView contains the views of two other…
David
  • 7,028
  • 10
  • 48
  • 95
0
votes
1 answer

collectionViewCells to collectionView position x:0, y:0

I am experiencing some layout issues with collectionViewCells. I am programmatically applying layout constraints and UICollectionViewCells are not being pinned to the 0,0 position in my collectionView. See attached screenshot for reference. Thanks…
0
votes
1 answer

row height is not automatically updated

EDITED: This is my custom cell class. It has a TextField and a TextView. Whatever I do I can't get the row height updated automatically. I know I can do it manually using heightForRowAt but I don't want to do that. class customCell: UITableViewCell,…
mfaani
  • 33,269
  • 19
  • 164
  • 293
1 2 3
99
100