【发布时间】:2015-09-21 11:31:02
【问题描述】:
如何重写视觉格式
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("|-[label]-|", options: .AlignAllBaseline, metrics: nil, views: ["label": label]))
addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[label]-|", options: .AlignAllCenterX, metrics: nil, views: ["label": label]))
通过移动到布局指南(带边距)?
我试过了
label.topAnchor.constraintEqualToAnchor(layoutMarginsGuide.topAnchor).active = true
label.leftAnchor.constraintEqualToAnchor(layoutMarginsGuide.leftAnchor).active = true
label.bottomAnchor.constraintEqualToAnchor(layoutMarginsGuide.bottomAnchor).active = true
label.rightAnchor.constraintEqualToAnchor(layoutMarginsGuide.rightAnchor).active = true
但不起作用。即使layoutMarginsGuide.layoutFrame 也没有预期值(是的,我在super 执行后将其称为layoutSubviews)。设置了约束,但行为就像零边距一样。只有当布局边距设置为负时,它才会布局并给出预期的layoutFrame;这显然不是我想要的,但表明约束是通过边距指南设置的。看来我错过了什么……
【问题讨论】:
标签: ios autolayout