0

我有一个很长的文本,我想重排并在禁用滚动的 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;

}

检查字符串的哪个部分适合单个视图,但仍然给我一个字符串长度超过适合 web 视图的长度。有没有办法拆分字符串以适应单个视图?

4

0 回答 0