Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write NSConstraint visual format language by including another button's width plus a constant

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

[button1(==button2)]

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

[button1(==button2+10)]

and

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

and both failed.. here is an error example:

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

(I obviously know you can do this by doing an NSStringWithFormat and simply filling in the variable in question.. but that looks too messy)

ideas?

P.S. just in case you're curious why I would like to stick with visual format language (as opposed to the other ways of doing it like this answer.. or using wrapper libraries out there.. check out this code sample)

like image 436
abbood Avatar asked Nov 16 '13 14:11

abbood


1 Answers

Some constraints can't be specified with the visual format language. You could use a simple constraint like this:

NSLayoutConstraint *c;
c = [NSLayoutConstraint constraintWithItem:button1 
                                 attribute:NSLayoutAttributeWidth 
                                 relatedBy:NSLayoutRelationEqual
                                    toItem:button2 
                                 attribute:NSLayoutAttributeWidth
                                multiplier:1.0 
                                  constant:10.0];
like image 97
DrummerB Avatar answered Oct 26 '22 08:10

DrummerB