Adding a restriction on the "main view" in xib

I have UIViewone defined in a .xib file. I need to install translatesAutoresizingMaskIntoConstraints = NO. This means that the frame does not translate into restrictions, so I need to set the size limits myself.

I created a working category method for UIView:

-(NSArray*)setSizeConstraints:(CGSize)size
{
    NSLayoutConstraint* height = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1  constant:size.height];
    NSLayoutConstraint* width = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1  constant:size.width];

    [self addConstraint:height];
    [self addConstraint:width];

    return [NSArray arrayWithObjects:height, width, nil];
}

But I would like to set these restrictions from the Xcode interface constructor, but all of my AutoLayout controls are grayed out: Xcode interface builder

Is there a way to do this in an interface builder?

+4
source share
2 answers

It is really possible.

, , , . enter image description here

.

, out . .

enter image description here

+1

, , Autolayout UIView Interface Builder.

( XIB: / (Xcode 6)) .

, , IB, :

  • UIViewController UIView XIB UIView
  • ( UIViewController)

, "", UIView, XIB.

0

Source: https://habr.com/ru/post/1546818/


All Articles