Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bouchtaoui-dev/efe1f71f23fcf8094387 to your computer and use it in GitHub Desktop.
Save bouchtaoui-dev/efe1f71f23fcf8094387 to your computer and use it in GitHub Desktop.
NSString* string = @"Hello World";
UIFont *font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:21];
CGSize constraint = CGSizeMake(300,NSUIntegerMax);
NSDictionary *attributes = @{NSFontAttributeName: font};
CGRect rect = [string boundingRectWithSize:constraint
options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
attributes:attributes
context:nil];
// Construct your label
UILabel* label = [[UILabel alloc] initWithFrame:rect];
[label setText:string];
[label setTextAlignment:NSTextAlignmentRight];
label.lineBreakMode = NSLineBreakByWordWrapping;
label.numberOfLines = 0;
[label setFont:font];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment