【问题标题】:Setting UITextView frame not working设置 UITextView 框架不起作用
【发布时间】:2013-02-22 22:51:28
【问题描述】:
CGRect tempframe = _infoText.frame;
tempframe.size.height = _infoText.contentSize.height;
_infoText.frame = tempframe;
[_infoText sizeToFit];
CGFloat height = _infoText.frame.size.height;
CGFloat start = _infoText.frame.origin.y;
_scrollView.contentSize = CGSizeMake(320, height+start);

这以某种方式为我提供了 _scrollView 的正确大小,但即使 _infoText.frame.size.height 目前是正确的,_infoText (UITextView) 也没有改变。也许之后它会变回原来的大小?我在 -viewDidLoad 之后 0.1 秒完成所有这些代码。

【问题讨论】:

    标签: xcode uiscrollview uitextview frame cgrect


    【解决方案1】:

    首先设置包含视图的大小。否则,嵌套文本视图可能会在其父视图调整大小时自动调整大小。另外,设置框架后不要调用sizeToFit

    【讨论】:

    • 我改变了它,以便我调用 _scrollView.contentSize = CGSizeMake(320,height+start);在我设置 _infoText.frame 之前,但这并没有改变结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-18
    相关资源
    最近更新 更多