【问题标题】:height of the text view to be dynamic inside a scrollview文本视图的高度在滚动视图中是动态的
【发布时间】:2013-06-11 07:29:16
【问题描述】:

我在滚动视图中有一个文本视图,我想让文本视图的高度作为其内容是动态的,因为我不想单独滚动文本视图,实际上我想滚动文本视图与滚动视图一起。

事实上,我对上图右侧的菜单感到困惑,关于约束高度等于、小于、大于、...

我不想让高度稳定,我希望它是动态的,在我的代码中:

 CGRect frame = self.detailTextView.frame;
    frame.size.height = self.detailTextView.contentSize.height;
    self.detailTextView.frame = frame;
    scroll.contentSize = CGSizeMake(scroll.contentSize.width,
                                    200 + self.detailTextView.frame.size.height);
    [self.detailTextView setFrame:frame];

其中detailTextView是文本视图的名称,scroll是滚动视图的名称。

但它不能正常工作,我该怎么办请帮忙!

注意:这个问题和(使用自动布局)的复选框有什么关系,因为它在我的应用程序中被选中

【问题讨论】:

  • 没有人来回答我?

标签: iphone ios xcode uiscrollview uitextview


【解决方案1】:

问题是什么?我只看到了一个问题,您需要禁用 youtTextView 的滚动。

【讨论】:

    【解决方案2】:

    CarinaM

    Use following method for getting dynamic height of textfield as per text. 
     -(CGFloat) GetHeightFoText:(NSString *)aStrTxt  FoWidth:(int)aIntWidth ForFontSize: (int)aIntFntSize
     {
      CGSize maximumLabelSize = CGSizeMake(aIntWidth,9999);
      CGSize expectedLabelSize = [text sizeWithFont:[UIFont systemFontOfSize:aIntFntSize]
                                constrainedToSize:maximumLabelSize
                                    lineBreakMode:UILineBreakModeWordWrap];
      return expectedLabelSize.height;
     }
    

    【讨论】:

    • 我需要文本视图的动态高度而不是文本字段
    • 您可以将它与 textfield、textview、webview(如果它包含 html 文本)、lable.Any 控件一起使用。在 textview 和 webview 中禁用滚动
    猜你喜欢
    • 2016-03-30
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2017-12-03
    • 1970-01-01
    • 2017-12-07
    相关资源
    最近更新 更多