Reputation: 3
layout code:
[leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(10, 10, 0, 0));
}];
[leftLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(10, 20, 100, 20));
make.width.equalTo(@(200));
}];
I want to set leftLabel's width with 200, but the result is not right, can you tell me the reason, thanks very much,
I have anther question, can I use mas_updateConstraints instead of mas_makeConstraints in any time?
Upvotes: 0
Views: 950
Reputation: 27620
When you set the edges of your label you indirectly define its width. So you should either set the edges OR the width. Not both. In your case if you want to set the label's width to 200 and keep the remaining three constants from your edge insets you should do it like this:
[leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@10);
make.left.and.bottom.equalTo(@0);
make.width.equalTo(@200);
}];
According to Masonry's docs you should use mas_updateConstraints
to update the constants of existing constraints. So you should probably only use it if you want to change some values on the constraints you defines earlier with mas_makeConstraints
Upvotes: 1