【问题标题】:iphone UitextView Text cut offiphone UitextView 文本被截断
【发布时间】:2009-09-29 00:38:25
【问题描述】:

我有一个用文本文件填充的 Uitextview。我在页面上有一个控件,允许用户启用和禁用分页。我遇到的问题是文本的顶部和/或底部线有时会“分成两半”,因此您只能看到该行的顶部或底部。我相信下面的代码应该可以解决它。代码获取文本的行高和框架高度,计算出屏幕上可见的行数,并创建一个新的框架高度以使其适合。虽然框架确实调整了大小,但它仍然“切断”了顶线和/或底线。有人有什么建议吗?我的数学错了吗?

谢谢!!!

 - (void)fitText
    {

            CGFloat maximumLabelHeight = 338;
            CGFloat minimumLabelHeight = 280;

            CGSize lineSize = [theUiTextView.text sizeWithFont:theUiTextView.font];
            CGFloat lineSizeHeight = lineSize.height;
            CGFloat theNumberOfLinesThatShow = theUiTextView.frame.size.height/lineSize.height;

            //adjust the label the the new height
            theNumberOfLinesThatShow = round(theNumberOfLinesThatShow);

            CGFloat theNewHeight = lineSizeHeight * theNumberOfLinesThatShow;

            if (theNewHeight > maximumLabelHeight)
        {
            theNumberOfLinesThatShow = theNumberOfLinesThatShow - 1;
            theNewHeight = lineSizeHeight * theNumberOfLinesThatShow;
        }
        if (theNewHeight < minimumLabelHeight)
        {
            theNumberOfLinesThatShow = theNumberOfLinesThatShow + 1;
            theNewHeight = lineSizeHeight * theNumberOfLinesThatShow;
        }

            //adjust the label the the new height.
            CGRect newFrame = theUiTextView.frame;
            newFrame.size.height = theNewHeight;
            theUiTextView.frame = newFrame;
}

【问题讨论】:

    标签: iphone uitextview


    【解决方案1】:

    UIScrollView(而 UITextView 是一个 UIScrollView)似乎在两边都使用了固定的 8 像素插图。这似乎与对齐或字体大小无关。

    所以,我认为您在这里缺少的是 16.0 的软糖因子 - 请参阅 this question.

    【讨论】:

      猜你喜欢
      • 2017-02-02
      • 2013-05-26
      • 1970-01-01
      • 2012-12-16
      • 2010-11-23
      • 2013-09-12
      • 2013-02-16
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多