Reputation: 13551
I am trying to set an icon to be 1/3 along the width of the superview.
However when I set the width it's only give me hard values as the option.
Is it possible to set the x position of an object to be 1/3rd the width through the interface builder?
Thanks
Update:
Trying to set a .leading against a .width does not appear to be an option for leading:
Upvotes: 1
Views: 643
Reputation: 104082
You should make the constraint between the icon's centerX and the superview's trailing. In the images below, first, and third refer to the first and third icons. The constraints will put the first one 1/3 of the way from the left edge, and the third one 1/3 of the way in from the right edge.
Upvotes: 5
Reputation: 746
You can constrain the widths to be equal with a multiplier of 1/3
Sorry misread question. You could do something like
// self.imageView is a reference to the image view (or view, whatever it is)
// and self.leadingConstraint is a constraint on the imageView's leading/X constraint
// probably have to recalculate on rotation (maybe, didn't test)
CGFloat constant = self.imageView.superview.frame.size.width / 3;
self.leadingConstraint.constant = constant;
[self.view layoutIfNeeded];
In IB
Not perfect but ¯_(ツ)_/¯
Upvotes: 0