How to write a visual format language NSConstraint, including one more button width plus constant

In the docs about the visual format language for NSLayoutConstraint there is an example where you set button1 to equal the width of button2:

 [button1(==button2)] 

my question is: is there a way to make button1 equal to button 2 with + constant .. I tried:

 [button1(==button2+10)] 

and

 [button1(==(button2+10))] 

and both failed. Here is an example error:

 A predicate on a view thickness must end with ')' and the view must end with ']' V:[tagWrapper(==tagButton+10)] ^' 

(I obviously know that you can do this by running NSStringWithFormat and just filling in the corresponding variable .. but it looks too dirty)

ideas?

PS Just in case, you are curious why I would like to stick with the language of the visual format (unlike other ways to do it like this answer .. or using the wrapper libraries there .. check this code example)

+6
source share
1 answer

Some restrictions cannot be specified using the language of the visual format. You can use a simple restriction like this:

 NSLayoutConstraint *c; c = [NSLayoutConstraint constraintWithItem:button1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:button2 attribute:NSLayoutAttributeWidth multiplier:1.0 constant:10.0]; 
+4
source

Source: https://habr.com/ru/post/958199/


All Articles