Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use drawRect with a subclass of UIScrollView?

I'm trying to implement an owner-drawn view that is a subclass of UIScrollView. Basically, I want to custom-draw the contents of the view, and then have the stuff I've drawn be scrollable.

I've overridden drawRect in my view and I'm able to draw my contents, scaled to the size of the UIScrollView's contentSize property (so some of my custom drawing is not visible, as I intended).

The problem is that the content then never moves. I can drag my finger up and down, and this makes the UIScrollView's scrollbars appear, but my custom-drawn content never moves or changes - I still always only see the top half.

How can I custom-draw content for this UIScrollView so that what I've drawn is scrollable?

like image 604
MusiGenesis Avatar asked Feb 24 '23 16:02

MusiGenesis


1 Answers

Are you calling [super drawRect]; at the end of your own drawRect method?

Edit

I misread the question. You'll need to create your own UIView subclass and put your overridden drawRect in that. Then, add that view as a child of the UIScrollView.

like image 168
Wex Avatar answered Mar 06 '23 18:03

Wex