1

いくつかの情報を表示するようにパネルを設定しようとしています。自動レイアウトを希望どおりに機能させるのに問題があります。

これが私がやろうとしていることです:

ここに画像の説明を入力してください

私はheaderView、UIImageView、5つのラベルを持っています。ラベルを垂直に並べて、UIImageViewから8間隔で配置したいと思います。私はそれらを垂直に簡単に並べることができます:

[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[headerView]-[acresLabel]-[addedLabel(==acresLabel)]-[typeLabel(==acresLabel)]-[zonesLabel(==acresLabel)]-[sceneLabel(==acresLabel)]-|"
                                                                    options:0
                                                                    metrics:nil
                                                                      views:NSDictionaryOfVariableBindings(headerView, acresLabel, addedLabel, typeLabel, zonesLabel, sceneLabel)]];

しかし、それらを画像ビューから整列させることは、退屈で冗長なことを証明しています。

[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView]-[acresLabel]"
                                                                    options:0
                                                                    metrics:nil
                                                                      views:NSDictionaryOfVariableBindings(imageView, acresLabel)]];

[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView]-[addedLabel]"
                                                                    options:0
                                                                    metrics:nil
                                                                      views:NSDictionaryOfVariableBindings(imageView, addedLabel)]];

[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView]-[typeLabel]"
                                                                    options:0
                                                                    metrics:nil
                                                                      views:NSDictionaryOfVariableBindings(imageView, typeLabel)]];

[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView]-[zonesLabel]"
                                                                    options:0
                                                                    metrics:nil
                                                                      views:NSDictionaryOfVariableBindings(imageView, zonesLabel)]];

[contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView]-[sceneLabel]"
                                                                    options:0
                                                                    metrics:nil
                                                                      views:NSDictionaryOfVariableBindings(imageView, sceneLabel)]];

これを行うためのより良い方法のように思えます。次に、画像ビューへの各ラベルに制約を設定します。最初の制約に追加しようとしNSLayoutFormatAlignAllCenterXましたが、すべての中心がコンテンツビューの中心Xに設定され、ラベルの中心Xが互いに整列していません。NSLayoutFormatAlignAllBaselineを垂直に使用すると、エラーとクラッシュが発生します。

データ(エーカー:'値')に対してこれを再度実行する必要があります。

4

1 に答える 1

6

あなたは正しい方向に進んでいNSLayoutFormatAlignAllCenterXます。CenterXを5つのラベルに揃えV:[headerView]-[acresLabel]たくないので、別の方法で行う必要があるのは、残りの制約から分離することだけです。headerView

// NSDictionary* views ;
[NSLayoutConstraint constraintsWithVisualFormat:@"V:[headerView]-[acresLabel]"  options:0  metrics:nil  views:views] ;
// Use any of the horizontal NSLayoutFormats (NSLayoutFormatAlignAllLeft, NSLayoutFormatAlignAllRight, NSLayoutFormatAlignAllLeading, NSLayoutFormatAlignAllTrailing, NSLayoutFormatAlignAllCenterX)
[NSLayoutConstraint constraintsWithVisualFormat:@"V:[acresLabel]-[addedLabel(==acresLabel)]-[typeLabel(==acresLabel)]-[zonesLabel(==acresLabel)]-[sceneLabel(==acresLabel)]-|" options:NSLayoutFormatAlignAllCenterX  metrics:0  views:views] ;
[NSLayoutConstraint constraintsWithVisualFormat:@"H:[imageView]-[acresLabel]"  options:0  metrics:nil  views:views] ;
于 2013-02-22T17:39:23.767 に答える