iOS: how to change the size of the UIScrollView content?

后端 未结 3 804
心在旅途
心在旅途 2021-02-06 13:00

I\'m now trying to create my own Text panel (with code highlighting and so on).

In fact everything is ready except one thing - scrolling

What I\'ve done: created

3条回答
  •  醉酒成梦
    2021-02-06 14:02

    It's simpler than you think, for example you have an UITextView called "textDesc" inside your UIScrollView, and you want to know the size of content, so next step will looks like that:

    int contentHeight = textDesc.frame.size.height + textDesc.frame.origin.y;
    

    After calculating the size of textDesc, just set it:

    [scrollView setContentSize:(CGSizeMake(320, contentHeight))];
    

    That's all, now your scrollView know the size of your text inside him, and will resize automatically, hope this helps, good luck.

提交回复
热议问题