Is is possible to offset a constraint by the size of another view in iOS?

808 Views Asked by At

I am using masonry to programmatically setup constraints on views. Several times I have wanted to offset a constraint by a characteristic of another view. Is that possible?

For example, I'd like to do this:

[self.someView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(self.mas_centerX).offset(self.otherView.mas_width);
}];

which of course doesn't compile because offset expects a number and not a constraint.

1

There are 1 best solutions below

1
On

Instead of self.otherView.mas_width in your offset, why not use self.otherView.frame.size.width? Use height instead of width if you want the height of the view. This is the correct way to get the width or height of a view.