【发布时间】:2014-10-05 23:18:28
【问题描述】:
我使用下面这行代码来设置按钮的大小:
self.toolsButton.frame.size = CGSizeMake(190, 40)
一切都很好,直到我添加以下布局约束:
var constrainToCenter = NSLayoutConstraint(item: toolsButton, attribute: .CenterX, relatedBy: .Equal, toItem: self.view, attribute: .CenterX, multiplier: 1.0, constant: 0.0)
self.view.addConstraint(constrainToCenter)
据我了解,此约束代码将按钮与视图水平居中,但为什么会对帧大小产生影响?如何在保持帧大小的同时也有约束?
【问题讨论】: