How to Add Constraint Between a View and the Top Layout Guide in a Xib File

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.

Sample Image

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.

Sample Image

Sample Image

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:

interface builder safe area



Related Topics



Leave a reply



Submit