I'm new to startup, but stumbled upon your question and thought it would be a good challenge. (This is my warning if this is not an ideal solution!)
You will need to add width limits in the code. I achieved this by first adding two views to the NIB with no width limits. These are the restrictions for the first (left) view:

These are the limitations that I had for the second (right) view:

This leaves an additional limitation that you do not want in the second view - the leading space between the supervisor and the second view, as shown below:

You cannot remove this restriction in IB, since it will leave an ambiguous layout (since we have no width in subviews). However, you can remove it in code. First, install a power outlet for it and plug it into IB:
@property (nonatomic, strong) IBOutlet NSLayoutConstraint *view2superviewLeadingConstraint;
Then in your viewDidLoad controller viewDidLoad you can remove it using:
[self.view removeConstraint:self.view2superviewLeadingConstraint]
Finally, add width limits. The key here is the multiplier parameter to determine what percentage you want the width to be based on the width of the supervisor. Also note that you must set the constant parameters to the start / end totals set in IB:
NSLayoutConstraint *constraint1 = [NSLayoutConstraint constraintWithItem:self.view1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:0.3 constant:-20]; [self.view addConstraint:constraint1]; NSLayoutConstraint *constraint2 = [NSLayoutConstraint constraintWithItem:self.view2 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:0.7 constant:-40]; [self.view addConstraint:constraint2];
Ian L Oct. 24 2018-12-12T00: 00Z
source share