添加约束的"主视图"在厦门国际银行 [英] Adding constraint to the "main view" in a xib

查看:194
本文介绍了添加约束的"主视图"在厦门国际银行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的UIView 中的.xib文件中定义。我需要设置 translatesAutoresizingMaskIntoConstraints = NO 。这意味着框架未转换为约束条件,所以我需要通过自己设置的大小限制。

I have a UIView defined in a .xib file. I need to set translatesAutoresizingMaskIntoConstraints = NO. This means that the frame is not translated to constraints so I need to set the size constraints by myself.

我已经创建了一个工作类方法的的UIView

I have created a working category method for a 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];
}

不过,我想设置从X code界面生成器这些限制,但我所有的自动版式控件是灰色的:

But I would like to set these constraints from the Xcode interface builder, but all my AutoLayout controls are greyed out:

有没有办法在界面生成器来做到这一点?

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

推荐答案

正如你一定发现了现在,它看起来像有目前没有办法在主设置自动布局约束的UIView 从Interface Builder的水平。

As you've surely found out by now, it looks like there's currently no way to set Autolayout constraints at the main UIView level from Interface Builder.

我这里有一个类似的问题(<一个href=\"http://stackoverflow.com/questions/28219842/launch-screen-xib-missing-width-height-constraints\">Launch屏幕厦门国际银行:缺少宽度/高度约束的),我的应用程序的启动屏幕工作时

I had a similar problem here (Launch Screen XIB: Missing Width / Height Constraints), while working with the launch screen of my app.

我发现,如果你想保持与IB工作的唯一的解决方法是:

The only workarounds I found, if you want to keep working with IB, are:


  • 使用的UIViewController 的UIView 的厦门国际银行里面,而不是仅仅一个的UIView

  • 只能用故事板工作(并再次,的UIViewController

  • Using a UIViewController and its UIView inside the XIB, instead of just a UIView
  • Working only with Storyboards (and, once again, UIViewController)

不过,我知道这些方法可能不理想,或干净的,特别是如果你只是有的UIView 的子类,你想画的接口在一个良好老厦门国际银行。

However, I understand these approaches may not be ideal or "clean", especially if you simply have a subclass of UIView and you want to draw its interface in a good old XIB.

这篇关于添加约束的&QUOT;主视图&QUOT;在厦门国际银行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆