First I create my new shortcut:
UILabel *newLabel=[[UILabel alloc] init]; newLabel.font=[UIFont preferredFontForTextStyle:@"Body"]; newLabel.translatesAutoresizingMaskIntoConstraints=NO; newLabel.numberOfLines=0; newLabel.lineBreakMode=NSLineBreakByWordWrapping; newLabel.text=[NSString stringWithFormat:@"This line is this: %@%@%@",resultString,resultString,resultString];
Then I create various constraints:
NSArray *labelConstraints=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[label]" options:0 metrics:nil views:@{@"label": newLabel}];
Unfortunately, the shortcut does not behave as expected. Assuming that I read the restriction above correctly, my label should go from one edge of the containing view to the other, horizontally and not snap to any given vertical height. This should, combined with my setting numberOfLines = 0 and lineBreakMode = NSLineBreakByWordWrapping, cause the cell to stretch horizontally to take all the necessary lines. Instead, the line stretches over the edge of the containing view to fit all onto one line — and I don't know why!
If that matters, [self] is a subclass of UITableViewCell, which I'm trying to program to dynamically scale with the size of the content. If I can just get the contents of the cell to cure myself correctly, calculating the actual cell size should be relatively simple!
source share