UISlider
のフォントサイズを変更する がありますUITextView
。フォント サイズを変更する前に、私UITextView
の高さがビュー コンテナーの高さよりも低くなるかどうかを確認したいと思います。問題は、sizeToFit
とsizeWithAttribute
が同じフォント サイズに対して異なる高さを返すことです。
そのために、カスタム fontSize を使用して高さを取得しようとしていますが、UITextView
その方法を理解できず、同じ高さを取得できない理由がわかりません。
self.photoDescription.text = @"Test"
self.photoDescription.font = [self.photoDescription.font fontWithSize:18];
[self.photoDescription sizeToFit];
NSLog(@"real height %f", self.photoDescription.frame.size.height);
//getting : 37.5
と:
NSLog(@"calculated height %f", [self.photoDescription.text sizeWithAttributes:@{NSFontAttributeName:[self.photoDescription.font fontWithSize:18]}].height);
//getting: 20.97
同じこと:
CGRect textRect = [self.photoDescription.text boundingRectWithSize:CGSizeMake(320, 300)
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[self.photoDescription.font fontWithSize:18]}
context:nil];
CGSize size = textRect.size;
NSLog(@"height %f", size.height);
// getting : 20.97
これについて何か考えはありますか?