views:

2717

answers:

2

My setup is a UIScrollView in the center of the screen (on the iPhone - like 300x400 positioned in the center) that contains a UIView of the same width, so it scrolls it vertically. In this UIView i draw custom subviews with labels etc (it's a scoreboard with various colors).

What i'd like to have is some shadow below my UIScrollView, so that the whole scrolling scoreboard floats over my background.

I have found this nice post http://stackoverflow.com/questions/805872/how-do-i-draw-a-shadow-under-a-uiview I use this code in my ScrollView subclass but it doesn't work for me. Maybe because I don't draw the actual shapes in the ScrollView's drawRect: (since they are drawn on the UIView).

Also I guess that in order to have the View scroll in the ScrollView and the shadow of the ScrollView outside the scrolling area, I guess I should extend the "bounds" of the ScrollView, right?

A: 

How about explicitly filling the entire self.bounds rectangle in your scroll view subclass' drawRect: method before calling super?

Another idea is to put the scroll view inside of another view which does the shadow drawing.

Daniel Dickison
+2  A: 

It's not quite clear to me what you're asking but, if you want the scrollView contents to scroll over a static image you simply need to add a UIView (or more likely a UIImageView) to your superview and then add your UIScrollView to that. If you set he background colour of the UIScrollView to be celarColor, the background image will show through - so you have a view heirarchy like:

  1. UIWindow
  2. UIView <----- your background here
  3. UIScrollView
  4. Scrolling subviews <----- high score table here

If you draw your highscore table in the scrolling subviews using CoreGraphics, the answer in the question you linked to will also work.

Roger Nolan
I'd rather not use a static image. Since my scores UIView height might change. It could be 2 lines, then 5 lines and then larger than the whole ScrollView height.
Dimitris
The approach works with a drawn background in view 2.
Roger Nolan
Just scale the image to correct size.
JOM