NSString *text = @"askdasfniuqwehnfunujgbnuyqbafyuhgbyusadfhbgvyhwreqwf";
_myLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 23, 175, 33)];
[_myLabel setFont:[UIFont fontWithName:@"Helvetica" size:30]];
[_myLabel setNumberOfLines:0];
[_myLabel setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:_myLabel];
_myLabel.backgroundColor = [UIColor redColor];
// UIFont *font = [UIFont fontWithName:@"Helvetica" size:30];//必须和Label的字体型号保持一致
UIFont *font = [UIFont systemFontOfSize:30];
CGSize size = CGSizeMake(320,2000); //设置一个行高上限
NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
size =[text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:tdic context:nil].size;
CGRect rect=_myLabel.frame;
rect.size=size;
[_myLabel setFrame:rect];
[_myLabel setText:text];
NSLog(@"%f--%f",_myLabel.frame.size.width,_myLabel.frame.size.height);
_myLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 23, 175, 33)];
[_myLabel setFont:[UIFont fontWithName:@"Helvetica" size:30]];
[_myLabel setNumberOfLines:0];
[_myLabel setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:_myLabel];
_myLabel.backgroundColor = [UIColor redColor];
// UIFont *font = [UIFont fontWithName:@"Helvetica" size:30];//必须和Label的字体型号保持一致
UIFont *font = [UIFont systemFontOfSize:30];
CGSize size = CGSizeMake(320,2000); //设置一个行高上限
NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
size =[text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:tdic context:nil].size;
CGRect rect=_myLabel.frame;
rect.size=size;
[_myLabel setFrame:rect];
[_myLabel setText:text];
NSLog(@"%f--%f",_myLabel.frame.size.width,_myLabel.frame.size.height);