UILabel *label      = [[UILabel alloc] init];
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.text          = text;
label.textAlignment = NSTextAlignmentCenter;
label.font          = [UIFont fontWithName:_bodyTextFontFamily size:_bodyFontSize];
CGSize size         = [label sizeThatFits:CGSizeMake(width, MAXFLOAT)];
float height        = size.height;
label.frame         = CGRectMake(x, y, width, height);

Source
Advertisements