【发布时间】:2014-02-15 19:34:06
【问题描述】:
我正在尝试将 UITextView 调整为其中文本的大小。 问题是我使用自定义字体,文本不适合 UITextView。
NSString *textToFit = @"pretty long text";
UIFont *customFont = [UIFont fontWithName:@"Museo-100" size:15];
CGSize sizeText = [textToFit sizeWithFont:customFont constrainedToSize:CGSizeMake(textFrame.size.width, 1000)];
其中 textFrame 是我要调整高度的 UITextView 的框架。
我正在尝试不同的字体以及相同字体的不同文件,但它仍然不会将其高度调整为文本填充的高度。
我一直在寻找,但没有找到解决方案。我已经尝试过使用 UILabel 和方法 textRectForBounds 的解决方法,但仍然没有成功,这行的东西。
UILabel *auxLabel = [[UILabel alloc]init];
auxLabel.numberOfLines = 0;
auxLabel.font = [UIFont fontWithName:@"Museo-100" size:15];
auxLabel.text = //THE TEXT I WANT TO FIT IN
CGRect textSize = CGRectMake(0.0, 0.0, textDescription.frame.size.width, FLT_MAX);
CGRect frame = [auxLabel textRectForBounds:textSize limitedToNumberOfLines:0];
【问题讨论】:
标签: objective-c uitextview uifont