私はそれが古いスレッドであることを知っていますが、それでもあなたが理解できなかった場合に備えて. これはバグであり、回避策として次の方法を使用できます。UITextField にカテゴリを作成し、次のメソッドを記述して、テキスト フィールドの幅に合わせてフォント サイズを変更する必要がある場合に呼び出します。
- (void)adjustFontSizeToFit
{
UIFont *font = self.font;
CGSize size = self.frame.size;
for (CGFloat maxSize = self.font.pointSize; maxSize >= self.minimumFontSize; maxSize -= 1.f)
{
font = [font fontWithSize:maxSize];
CGSize constraintSize = CGSizeMake(size.width, MAXFLOAT);
CGSize labelSize = [self.text sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
// Keeping the width constant if given text requires more height , decrease the font size.
if(labelSize.height <= size.height)
{
self.font = font;
[self setNeedsLayout];
break;
}
}
// set the font to the minimum size anyway
self.font = font;
[self setNeedsLayout];
}