我的最终目标是改变字体大小,以便各种单词适合相同的矩形区域.我认为sizeWithFont将是一个很好的方法,但我不断得到宽度为0,我很困惑.
NSString *name = @"Test Word";
CGFloat fontSize = 32.0;
UIFont *font = [UIFont fontWithName:@"TimeNewRomanPSMT" size: fontSize];
CGSize sWidth = [name sizeWithFont:font
constrainedToSize:CGSizeMake(fontSize, CGFLOAT_MAX)
lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"sWidth = %3.1f; rec.width n= %3.1f ", sWidth.width, rec.width);
Run Code Online (Sandbox Code Playgroud)
我的计划是循环遍历字体大小,直到宽度适合但sWidth.width保持返回0.
克里斯