在代码中设置的约束不会反映在输出(Autolayout iOS)

我有两个视图,我已经采取了故事板,但我没有在故事板中设置任何布局。我想设置它们的代码。所以这就是我所做的:

我读了一个视图的autoResizingMask属性和'translatesAutoResizingMaskIntoConstraints'。所以将'translatesAutoResizingMaskIntoConstraints'设置为'NO'是有道理的。所以我已经做了,但仍然无法以编程方式设置约束。现在,由于一些约束被自动设置在故事板上,当我们从故事板中获取观点时,我尝试了:

[self.view removeConstraints:[self.view constraints]]; 

这样做后,它会从超级视图(即self.view)中删除所有的默认约束。但是我仍然无法设置代码约束。我该怎么办?我需要一些指导。

这是我一直在使用的代码:

  [self.view setTranslatesAutoresizingMaskIntoConstraints:NO]; NSLayoutConstraint *layouts1 = [NSLayoutConstraint constraintWithItem:_redView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:_yellowView attribute:NSLayoutAttributeWidth multiplier:3.0f constant:100.0f]; [self.view addConstraint:layouts1];