Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created June 29, 2011 07:14
Show Gist options
  • Save marshluca/1053312 to your computer and use it in GitHub Desktop.
Save marshluca/1053312 to your computer and use it in GitHub Desktop.
计算UILable的宽度
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