//使用时,font指定字体和最大字体大小,minFontSize指定最小字体,actualFontSize传递实际大小的引用。width指定总宽度,lineBreakMode指定换行模式。 |
2 | - (CGSize)sizeWithFont:(UIFont *)font |
3 | minFontSize:(CGFloat)minFontSize |
4 | actualFontSize:(CGFloat *)actualFontSize |
5 | forWidth:(CGFloat)width |
6 | lineBreakMode:(UILineBreakMode)lineBreakMode |
例子:
01 | UILabel *_label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 320)]; |
02 | [_label setNumberOfLines:0]; |
03 | CGFloat fontSize; |
04 | NSString *testString = @ "All hail Sakuya!" ; |
05 | UIFont *font = [UIFont systemFontOfSize:100]; |
06 | [testString sizeWithFont:font |
07 | minFontSize:7.0f |
08 | actualFontSize:&fontSize |
09 | forWidth:(320) |
10 | lineBreakMode:NSLineBreakByCharWrapping]; |
11 | [_label setFont:[UIFont systemFontOfSize:fontSize]]; |
12 | [_label setText:testString]; |
13 | [self.view addSubview:_label]; |