Autolayout: Add constraint to superview and not Top Layout Guide?
There is an arrow to the right of the constraint constant value. If you click on it, a menu pops out where you can choose what is it that you want to make your constraint relative to. If you choose 'View', than it will pin it to the top of the view.
How can I add a contraint to the root view instead of TopLayoutGuide?
self.automaticallyAdjustsScrollViewInsets = true
The default value of this property is true, which lets container view controllers know that they should adjust the scroll view insets of this view controller’s view to account for screen areas consumed by a status bar, search bar, navigation bar, toolbar, or tab bar. Set this property to false if your view controller implementation manages its own scroll view inset adjustments.
You can also set this property from Interface Builder
Is there any way to add constraint between a view and the top layout guide in a xib file?
You should refer the following example, this will definitely help you for your problem. I got this from http://developer.apple.com .
[button setTranslatesAutoresizingMaskIntoConstraints: NO];
id topGuide = myViewController.topLayoutGuide;
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (button, topGuide);
[myViewController.view addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat: @"V:[topGuide]-20-[button]"
options: 0
metrics: nil
views: viewsDictionary]
];
Weird behaviour with constraints to top / bottom layout guide
So I found a hint here:
https://www.youtube.com/watch?v=lxc9DnqpI0c
And anyway the trick is to NOT constraint a subview to the top / bottom layout guides, but rather to the superview.
Basically if you want to set a constraint between a subview (not the main view) to the top / bottom of the screen, do not use the usual ctrl+drag technique, but just select it and then go:
Editor > Pin > Top Space to Superview
Spent some few hours on this!
constrain view.bottom to superview.bottom not bottomLayoutGuide in storyboard
Select your TableView and go to Editor -> Pin
.
From there you have 4 options to pin to superview:
- Leading Space to Superview
- Trailing Space to Superview
- Top Space to Superview
- Bottom Space to Superview
This works as expected. The only downside is that you have to perform the pinning manually, as there are no shortcuts available.
How to set layout constraints with top layout guide?
|
refers to the superview, so you are creating a constraint that is pinning the view to the top of the superview.
You need to add the top layout guide as an item in your VFL string:
id guide = self.topLayoutGuide;
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[guide][button]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(guide,button)]];
Add spacing constraint to superview in Xcode 5
To add a constraint between a view and its' superview (like "bottom space to superview") you can use the Document Outline (The left part of the Interface Builder).
In the Document Outline:
- Hold the ctrl-key and drag from the view to its' superview (or vice versa).
- Select the constraints you want to add (in this example "Bottom Space to Container").
iOS 7 AutoLayout Top Space to Top Layout Guide Without Control-Drag in Interface Builder?
You can use the "nearest neighbour" popover in the bottom. Select the top line and click "Add 1 constraint".
This will default your constraint to the top layout guide as shown in the second screenshot below.
equal distance from top layout guide and bottom layout guide
Add another UIView
with constraints with top and bottom layout guide. Then add your view as a subview and align vertically and horizontally.
Related Topics
Module Compiled with Swift 4.2.1 Cannot Be Imported by the Swift 5.0 Compiler
Swift 3 - Comparing Date Objects
Expand Uilabel Inside Uitableview with "More" Button Like Instagram
Install Apps on Device Without Itunes
How to Access Both Objective-C and Swift Classes from Same Storyboard
Exc_Bad_Instruction When Passing Uicollectionview Cell Data to Different Viewcontroller
Calculating Bearing Between Two Cllocation Points in Swift
Error: Ld: Library Not Found for -Lpods with Cocoapods
Offscreen Uitableviewcells (For Size Calculations) Not Respecting Size Class
Restore Already Bought In-App-Purchases on Iphone
Centering Mkmapview on Spot N-Pixels Below Pin
Cocoa-Touch: How to See If Two Nsdates Are in the Same Day
Xcode - Mpnowplayinginfocenter Info Is Not Displayed on iOS 8
How to Create a User with Multiple Attributes in Firebase with Swift
App Not Sized Properly iOS 8 iPhone Simulator
Linker Error in iOS (Duplicate Symbols for Architecture X86_64)