如何在 swift 3.0 中使用砌体

how to use masonry in swift 3.0

Objective-C

[textView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.mas_equalTo(UIEdgeInsetsZero).priorityLow();
    make.top.mas_equalTo(imageView.mas_bottom).offset(20);
}];

我想更改 swift 代码。请帮我??谢谢。

这些代码可以工作

btn.mas_makeConstraints { (make:MASConstraintMaker?) in
    make?.top.equalTo()(view.mas_top)?.with().offset()(0)
    make?.left.equalTo()(view.mas_left)?.with().offset()(0)
    make?.right.equalTo()(view.mas_right)?.with().offset()(0)
    make?.bottom.equalTo()(view.mas_bottom)?.with().offset()(0)
    return()
}

您也可以使用SnapKit, which is the Swift only version of Masonry. It looks like they have decided not to deprecate Masonry, as was previously the case, but is still a good idea for your Swift only projects. If you are familiar with Masonry,您可以非常轻松地迁移到SnapKit。

最短的方法(如果你想镜像edges父视图是)

    self.xibView .mas_makeConstraints( { make in
        _ = make?.edges.equalTo()(self)
    })

这个赋值 _ = 也会消除关于取消赋值的警告。