【问题标题】:UITextView text is missing when adjust frame according to text in iOS7?根据iOS7中的文本调整框架时UITextView文本丢失?
【发布时间】:2014-06-09 11:59:03
【问题描述】:

您好,我正在尝试根据内容设置 UITextView 高度。它可以很好地调整 UITextView 的框架。

但是如下图所示,缺少文本。这仅在 iOS7 中发生。它在iOS6中显示良好。如果我点击 textview 我开始编辑 textview 完整的文本正在显示。

我写了下面几行代码`notesField.text = [editWellObject objectForKey:@"Notes"];

// Adjusting Frame as per text
CGSize size = [notesField sizeThatFits:CGSizeMake(notesField.frame.size.width, FLT_MAX)];
CGRect frame = notesField.frame;
float difference = size.height - frame.size.height;
frame.size.height = size.height;
notesField.frame = frame; 

请帮助我解决这个问题。提前致谢。

【问题讨论】:

  • 我也有同样的问题,所以我将高度增加了 10,即它对 size.height 的附加。享受:)
  • 感谢王子的回复。但这里的 UITextView 框架更多来自文本。这里的绿色层边界超出了textview。这意味着它有框架直到底部。

标签: ios7 uitextview frame cgsize


【解决方案1】:

几天前,我一直在为同样的问题苦苦挣扎,我找到了将属性 scrollEnable 从 NO 重置为 YES 的解决方案。以下是我的代码 sn-p

    internalTextView.scrollEnabled = NO;
    if (newSizeH >= maxHeight)
        internalTextView.scrollEnabled = YES;

【讨论】:

  • 谢谢@Raman Soni 请你解释一下什么是newSizeH?
  • 它的变量存储你的文本动态高度。这是完整的代码 sn-p: CGSize dynamicSize = [uitextviewinstance.text sizeWithFont:uitextviewinstance.font constrainedToSize:CGSizeMake(uitextviewinstance.frame.size.width-uitextviewinstance.contentInset.left-uitextviewinstance.contentInset.right, constraintHeight) lineBreakMode:NSLineBreakByWordWrapping] ;浮动 newSizeH = size.height; internalTextView.scrollEnabled = 否; if (newSizeH >= maxHeight) internalTextView.scrollEnabled = YES;注意:maxHeight 是 UI 上 uitextviewinstance 允许的最大高度
猜你喜欢
  • 1970-01-01
  • 2013-06-11
  • 1970-01-01
  • 2013-11-19
  • 1970-01-01
  • 2021-06-28
  • 1970-01-01
  • 1970-01-01
  • 2011-03-01
相关资源
最近更新 更多