samedi 27 décembre 2014

Vertical spacing setting programmatically hides the label content in ios

I have searched for this problem all over the programming site but i did not get the answer. So I am writing here. I have a tableViewController, in that i am using custom cell using xib. It contains 4 labels, Each one is appeared by bottom of others. Now I feed the content programmatically, so label1 has number of lines and label2 has number of lines. Now the problem is the contents of label1 and label2 is messed up. I am using the following code:



[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.label1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.label2 attribute:NSLayoutAttributeTop multiplier:1 constant:0.0]];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.label1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.image1 attribute:NSLayoutAttributeTop multiplier:1 constant:0.0]];

NSArray *constraint_H_label1 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[goalDescription(274)]" options:0 metrics:nil views:contentDictionary];

NSArray *constraint_POS_H_label1 = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-18-[label1]" options:0 metrics:nil views:contentDictionary];
NSArray *constraint_POS_V_label1 = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-31-[label1]" options:0 metrics:nil views:contentDictionary];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.label1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.label2 attribute:NSLayoutAttributeTop multiplier:1 constant:0.0]];


What I want is, if label1 has 4 lines then the label2 should start after the 4th line of label1. But I dont know how to use this without activating autolayout in xib.


Can anyone help me to solve this issue?


Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire