I use Adaptive layout features for designing an app. I take a IBOutlet
of an "Aspect Ratio" constraint . I want to change the value of this Aspect Ratio Value to the double of current value. The problem is that "constraint
" property can be set easily from Code, but "multiplier
" property is read only property. For Aspect Ratio Change, "multipier" value change is necessary . How Could I do this?.
@property (retain, nonatomic) IBOutlet NSLayoutConstraint *leftImageWidthAspectRatio;
In code
NSLog(@"cell.leftImageWidthAspectRatio:%@ : %lf %lf",cell.leftImageWidthAspectRatio, cell.leftImageWidthAspectRatio.constant,cell.leftImageWidthAspectRatio.multiplier);
Results that
cell.leftImageWidthAspectRatio:<NSLayoutConstraint:0x7c9f2ed0 UIView:0x7c9f2030.width == 2*RIFeedThumbImageView:0x7c9f2c90.width> : 0.000000 2.000000
You’re right—changing the multiplier on an existing constraint isn’t supported.
constant
is the exception, not the rule. From the docs:What you need to do is what’s described at the end there: replace the existing constraint with an identical-but-with-a-different-multiplier one. Something like this should work:
Note that
cell
may be the wrong view for this—it depends where IB decides to put the original constraint. If that doesn’t work, dig up through the superviews of the constrained views (you can check what constraints they have with theconstraints
property) until you find where it’s ending up.