1
votes

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 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?

2
I just used a UIImageView and had the shadow in an image in the end. I didn't manage to get anything else to work.Dimitris

2 Answers

2
votes

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.

0
votes

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.