iOS ui界面vtf 开发

时间:2021-07-30 15:55:02

addConstraints

添加约束的步奏

  1. 添加控件到view中
  2. 设置translateResizeLayoutintoautolayout = false
  3. 添加约束

    注意

    约束 : 出现 有父子关系的约束时候

    【父 addConstarints 子】

注意

/**
* 两个子控件不可以添加相对的view
必须是
父亲 = 子 * mul +constant
*/ // 相对约束

// NSLayoutConstraint * blueRight = [NSLayoutConstraint constraintWithItem:blueview attribute:NSLayoutAttributeLeftMargin relatedBy:NSLayoutRelationEqual toItem:redview attribute:NSLayoutAttributeRightMargin multiplier:0.0f constant:50];

//

// [blueview addConstraint: blueRight];

// [redview addConstraint: blueRight];

报出来的错误

[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]: A multiplier of 0 or a nil second item together with a location for the first attribute creates an illegal constraint of a location equal to a constant. Location attributes must be specified in pairs'