Forked from baphillips/iOS-7-boundingRectWithSize-options-attributes-context.m
Last active
August 29, 2015 14:25
-
-
Save bouchtaoui-dev/efe1f71f23fcf8094387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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