Created
June 29, 2011 07:14
-
-
Save marshluca/1053312 to your computer and use it in GitHub Desktop.
计算UILable的宽度
This file contains hidden or 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
myLable=[[UILabel alloc] initWithFrame:CGRectMake(0, 23, 175, 33)]; | |
[myLable setFont:[UIFont fontWithName:@"Helvetica" size:10.0]]; | |
[myLable setNumberOfLines:0]; | |
[myLable setBackgroundColor:[UIColor clearColor]]; | |
[myAdView addSubview:myLable]; | |
UIFont *font = [UIFont fontWithName:@"Helvetica" size:10.0]; | |
CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(175.0f, 2000.0f) lineBreakMode:UILineBreakModeWordWrap]; | |
CGRect rect=myLable.frame; | |
rect.size=size; | |
[myLable setFrame:rect]; | |
[myLable setText:text]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment