2016-03-19 2 views
-2

ストーリーボードを介していくつかのテキストフィールドを垂直に追加しました。それらの下に、プログラムでテキストフィールドを追加したいのですが、常に1つのテキストフィールドしか追加しません。以下は enter image description hereiOSでテキストフィールドを垂直方向に追加できませんか?

コードが

int i; 
    self.main_view.translatesAutoresizingMaskIntoConstraints = NO; 
    self.scroll_view.translatesAutoresizingMaskIntoConstraints = NO; 

    for (i=0; i<[arr_customEdtTxt count]; i++) 
    { 
     JVFloatLabeledTextField *tf = [[JVFloatLabeledTextField alloc] initWithFrame:CGRectMake(25, y, 270, 27)]; 
     tf.textColor = [UIColor blackColor]; 
     tf.font = [UIFont fontWithName:@"Helvetica" size:14]; 
     CustomEditText *custom=[arr_customEdtTxt objectAtIndex:i]; 
     tf.placeholder=custom.field_name; 
     tf.textAlignment=NSTextAlignmentLeft; 

     previousTextfield=tf; 
     //add bottom border 
     [self addBorder:tf]; 
     tf.translatesAutoresizingMaskIntoConstraints = NO; 
     [self.main_view addSubview:tf]; 
     y=y+27; 

     [self.main_view addConstraint:[NSLayoutConstraint constraintWithItem:tf attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.main_view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0] ]; 

     [self.main_view addConstraint:[ NSLayoutConstraint constraintWithItem:tf 
            attribute:NSLayoutAttributeHeight 
            relatedBy:NSLayoutRelationEqual 
             toItem:nil 
            attribute:NSLayoutAttributeHeight 
            multiplier:1.0 
             constant:27.0]]; 
     [self.main_view addConstraint:[ NSLayoutConstraint constraintWithItem:tf 
                    attribute:NSLayoutAttributeWidth 
                    relatedBy:NSLayoutRelationEqual 
                     toItem:self.txt_email 
                    attribute:NSLayoutAttributeWidth 
                    multiplier:1.0 
                     constant:0]]; 
     if(i==0) 
     { 
      [self.main_view addConstraint:[NSLayoutConstraint constraintWithItem:tf attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.txt_exprience attribute:NSLayoutAttributeBottom multiplier:1 constant:15.0f]]; 
     } 
     else 
     { 
      [self.main_view addConstraint:[NSLayoutConstraint constraintWithItem:tf attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:previousTextfield attribute:NSLayoutAttributeBottom multiplier:1 constant:15.0f]]; 
     } 
     [arr_tf addObject:tf]; 
    } 

    [self.main_view layoutIfNeeded]; 
    [self setDatatoFields]; 

を使用している私は私が

の下に、より多くのテキストfiledsを追加する方法を教えてfields.Please現在のテキストの下にテキストフィールドを追加したい制約エラーを取得しています

答えて

0

それはpreviousTextfieldtfのように見えるが、このラインで同じテキストフィールドを参照してください。

[self.main_view addConstraint:[NSLayoutConstraint constraintWithItem:tf attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:previousTextfield attribute:NSLayoutAttributeBottom multiplier:1 constant:15.0f]]; 
if(i > 0){ 
    //Change arr_tf for arr_customEdtTxt if that is your array 
    previousTextfield = [arr_tf objectAtIndex:i-1]; 
} 
:はまた、私はあなたと previousTextfield = tfを変更する必要がありTextFieldのあなたの配列がされて最後にあなたが arr_tfにTextFieldを追加しますが、あなたもその1に応じた arr_customEdtTxtを持っていることに気づきました
関連する問題