how to use masonry in swift 3.0
Asked Answered
M

3

5
Objective-C

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

I want change swift code. please help me?? thanks.

Maladjusted answered 6/9, 2016 at 3:25 Comment(1)
What do you want to do and what is your problem? What have you tried to solve it yourself?Mufti
V
7

These code make work

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()
}
Volcanic answered 29/9, 2016 at 6:10 Comment(0)
S
2

The shortest way to do it (if you want to mirror edges of parent view is)

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

This assignment _ = also will silence the warning about un-assignment.

Slacker answered 7/12, 2016 at 15:44 Comment(0)
K
0

You can also use 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, you can migrate to SnapKit very easily.

Kashakashden answered 4/11, 2016 at 11:38 Comment(2)
The only caveat to my own advice is that SnapKit support doesn't go back very far. I've run into support issues for macOS, they only support 10.11+.Kashakashden
Some people have to not use swift frameworks unfortunatlySemination

© 2022 - 2024 — McMap. All rights reserved.