我有一个很长的文本,我想要重排并在带有禁用滚动的uiwebview中显示。我尝试使用此代码:
-(NSInteger)lengthOfString:(NSString *)str
thatFitsIntoView:(UIView *)displayView
withFont:(UIFont *)font
{
CGSize textSize = [str sizeWithFont:font
constrainedToSize:displayView.frame.size
lineBreakMode:NSLineBreakByWordWrapping];
NSInteger lengthThatFits;
CGFloat display = 414.000000;
NSLog(@"%f -%f",displayView.frame.size.width,textSize.height);
if (textSize.height > displayView.frame.size.width)
{
lengthThatFits = str.length * display / textSize.height;
}
else
{
lengthThatFits = str.length;
}
return lengthThatFits;
}
要检查字符串的哪个部分适合单个视图,但仍然给我一个字符串长度超过适合webview的字符串长度。有没有办法拆分字符串以适合单个视图?