我正在尝试找到一种不推荐使用的方法来缩小 textview 的字体大小,以便所有文本都适合 textview 而无需滚动。
'sizeWithFont' 方法已被弃用,我想确保最佳实践,XCode 说要使用'boundingRectWithSize',但不确定如何使用它来缩小字体大小以使所有文本都适合。
有什么建议么?不,我不能使用 UILabel 代替。我需要让文本在顶部垂直对齐,而 UILabel 不这样做。
这在 iOS 7 之前有效:
CGFloat fontSize;
CGFloat minSize;
if([deviceType isEqualToString:@"iPad"] || [deviceType isEqualToString:@"iPad Simulator"]){
fontSize = 40;
minSize = 15;
}
else{
fontSize = 18;
minSize = 8;
}
while (fontSize > minSize)
{
CGSize size = [quote sizeWithFont:[UIFont fontWithName:@"Interstate" size:fontSize] constrainedToSize:CGSizeMake(newView.frame.size.width, 10000)];
if (size.height <= newView.frame.size.height) break;
fontSize -= 1.0;
}