I am writing a code that dynamically creates labels and realigns the labels relative to the last label created. I am using the following code to create and resize the height of the label to fit the content.
// Create label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.text = SomeVariatingTextContent;
[self.scrollView addSubview:label];
// Resize Label
UIFont* font = label.font;
CGSize constraintSize = CGSizeMake(label.frame.size.width, MAXFLOAT);
CGSize labelSize = [label.text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeTailTruncation];
label.frame = CGRectMake(label.frame.origin.x, label.frame.origin.y, 280, labelSize.height);
How do find the identifier to the previous label such that I can realign the the next label being created such that it is always 8 points below the previous label created?
Try to use CGRectGetMinY etc. (look here: CGGeometry Reference to get the edges of previous UILabel, for example:
EDIT
I can assume that the last UILabel is the last one you added to the view so you can:
Br aware that if you have other subviews added later you need to filter the array to get the UILabels only. if the order is the problem you can get all the labels and check their y position to get the last one.
An other way is too store save a pointer to the UILabel at the end of the loop that creates the labels, and update that pointer every time a new label is created.