如何找到允许所有文字适合UITextView 的最大字体大小,而不将单个字词拆分为多行?我在网上发现了类似的问题,但所有答案都提供了分割单个单词的代码。
我认为以下内容可行,但单个单词仍然分成多行。
UIFont *tempFont = [UIFont fontWithName:font size:MIN_FONT_SIZE];
while ([snippetTextView.text sizeWithFont:tempFont constrainedToSize:CGSizeMake(textViewWidth, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping].height < textViewHeight)
{
tempFont = [tempFont fontWithSize:tempFont.pointSize + 1];
}
snippetTextView.font = tempFont;