Search code examples
xcodeuiviewdrawinguislider

How to update a subclassed UIView for drawing when the slider is changed?


Some time ago I saw this on one of the iTunes U movies (I think it was stanford). I can't find the exact video unfortunately... So if you know please tell me.

I want to create a view where the user can use the slider to change the smiley face.

So my current plan is to subclass UIView, then use drawInRect to make the drawing. But how do I hook the slider value to my drawing and how do I update it 'smoothly'?


Solution

  • In your value changed handler for the slider, ask the view to redraw itself. The view should clear its context first, then do whatever it needs to do given the inputs you'll pass to it (the value of the slider) before asking it to redraw itself using -setNeedsDisplay et al.