0

NSButtonコードで NSView に未定義の数を追加する必要があります。問題は、ボタンconstraintsWithVisualFormat:の名前とボタンの数がわからないため、使用できNSButtonないことです。誰にも解決策がありますか?ありがとう!

4

1 に答える 1

0

When using constraintsWithVisualFormat:, you need to know the names of the variables that point to your NSButtons only if you use NSDictionaryOfVariableBindings to create the dictionary of views. You could just as easily build your own dictionary using whatever keys you like.

If your buttons are stored in an array, you can iterate through them and create constraints between each of them:

for ( int i = 1 ; i < buttonArray.count ; i++ ) {
    NSDictionary* views = @{ @"buttonOne":buttonArray[i-1] , @"buttonTwo":buttonArray[i] } ;
    NSArray* constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"[buttonOne]-[buttonTwo]"  options:0  metrics:nil  views:views] ;
    // Use the constraints.
}
于 2013-06-02T17:36:14.550 に答える