How to use drawRect with a subclass of UIScrollView?

I am trying to implement an owner-created view that is a subclass of UIScrollView . Basically, I want to draw the contents of a view, and then draw scrollable material.

I overridden drawRect in my opinion, and I can draw my content scaled to the size of the UIScrollView contentSize property (so some of my custom drawings do not display, as I expected).

The problem is that the content never moves. I can drag my finger up and down, and this leads to the appearance of UIScrollView scrollbars, but my custom content never moves or changes - I still always see only the top.

How can I draw the contents for this UIScrollView so that what I draw scrolls?

+4
source share
1 answer

You call [super drawRect]; at the end of your own drawRect method?

Edit

I misunderstood the question. You need to create your own subclass of UIView and put an overridden drawRect in it. Then add this view as a child of the UIScrollView .

+6
source

Source: https://habr.com/ru/post/1345750/


All Articles