Presumably you've got any array of names. What you'll do is enumerate the list of names, determine the lengths required for each one, and then store the greatest one and apply it as the desired width. You will need to define a "maximum size" that should not be exceeded. A method along these lines should return something suitable:
- (CGFloat)suitableWidthForLabel:(UILabel *)nameLabel withNames:(NSArray *)arrayOfNames
{
CGFloat suitableWidth = 100.0f; // A reasonable starting point
CGSize maximumSize = CGSizeMake(600.0f, nameLabel.frame.size.height);
UIFont *labelFont = [nameLabel font];
for (NSString *aName in arrayOfNames)
{
CGSize expectedLabelSize = [aName sizeWithFont:labelFont
constrainedToSize:maximumSize
lineBreakMode:nameLabel.lineBreakMode];
suitableWidth = MAX(suitableWidth, expectedLabelSize.width);
}
return suitableWidth; // This will be the largest size you may need to accommodate
}