私は2つのラベルを持っています。どちらかが動いたら両方動かせるようにしたいです。それらを NSLayoutConstraints と一緒に「アタッチ」するにはどうすればよいですか? IB でこれを行うことができますが、コードで行う必要があります。
また、NSLayoutAttributeBaseline、NSLayoutAttributeLeading、および NSLayoutAttributeTrailing とは何ですか?
編集:
センタリング poweredByLabel (別名 label02):
[constraints addObject:[NSLayoutConstraint constraintWithItem:poweredByLabel
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:myImage
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0]];
ラベルを積み重ねて垂直に切り替えます。
[constraints addObjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[rememberPasswordSwitch]-10-[rememberPasswordLabel]-10-[versionLabel]-[poweredByLabel]-|"
options:NSLayoutFormatAlignAllBaseline
metrics:nil
views:viewsDictionary]];
エラーが発生します:
*キャッチされない例外 'NSInvalidArgumentException' が原因でアプリを終了しています。V:[rememberPasswordSwitch]-10-[rememberPasswordLabel]-10-[versionLabel]-[poweredByLabel]-|...................................................... ................................................................... ...................^'
NSLayoutFormatAlignAllBaseline オプションを指定しないと、正常に実行されます (スタックされますが、すべてが水平方向に中央揃えされるわけではありません)。