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]
];
Add top layout guide in NIB file (XIB)]
You can do this by by implementing new property called edgesForExtendedLayout in iOS7 SDK
-(void)viewDidLoad {
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
}
or
If you are using navigation bar and xcode5 then..
In Interface Builder,select view controller, and then navigate to the attributes inspector. In "Extend Edges". check Under Top Bars
i have solved my problem from Here
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.
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.
iOS - Top Layout Guide height issues
With iOS 11, Apple is deprecating top(bottom)LayoutGuide
and switching to the safeAreaLayoutGuide
. In code, you could pin your view using view.safeAreaLayoutGuide.topAnchor
, but in storyboards you'll want to pin stuff to the safe area node inside your view controller's view:
Related Topics
iOS App, Programmatically Get Build Version
iOS Certificate Pinning with Swift and Nsurlsession
Invalid Update: Invalid Number of Items on Uicollectionview
A Launch Storyboard or Xib Must Be Provided Unless the App Requires Full Screen
Undefined Symbols for Architecture Armv7 When Using Zxing Library in Xcode 4.5
Download Xcode 4.2 Documentation for Offline Install
Icloud + Coredata - How to Avoid Pre-Filled Data Duplication
Getting User's Personal Info from Facebook in iOS
"File Not Found", "Linker Command Failed with Exit Code 1" in Xcode 4.5.1
Invalid Signature - Code Object Is Not Signed at All
Return Lighter Color from Skcolor Using Hsl Lightness Factor
Why I Couldn't Assign Fetched Values from Firestore to an Array in Swift
Detected a Case Where Constraints Ambiguously Suggest a Height of Zero
Uiwebview VS Wkwebview to Load Local HTML
What Is the Meaning of This Declaration