Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the background of UIScrollView to be transparent?

What i ultimately would LOVE to do is having my scroll view contents scrolling (in the scroll view control), and have a static background (a wallpaper image).

I've tried a combination of things, none of which really yields what im looking for, not even close really.

Has anybody attempted this before?

like image 525
Edward An Avatar asked Aug 12 '09 04:08

Edward An


3 Answers

This is actually very easy, a UIScrollView inherits from a UIView so you just need to set the backgroundColor property:

aScrollView.backgroundColor = [UIColor clearColor];

The above line of code sets the background to transparent so you can see through to whatever you want to put behind. Note also that you should do the same thing to the sub-views that you put inside the scroll-view - those views should also have a transparent background colour.

If you want a static image, use a pattern as in the line of code below. This can be a texture image smaller than the screen that will be repeated/tiled, or a full-screen image so you don't see any repeats.

aScrollView.backgroundColor = [UIColor colorWithPatternImage:anImage];
like image 189
jhabbott Avatar answered Sep 29 '22 17:09

jhabbott


For those not having clear answer to this. It goes:

put an dummy holder imageview to the mainview and set it to the desired background image or set its backcolor as pattern, then inside this view put the scrollview and set its background to transparent.

Then you get the desired effect as with Safari on iPad for example on page scroll.

This is a code for Monotouch, but is straightforward to understand.

this.View.BackgroundColor = UIColor.FromPatternImage (UIImage.FromFile ("Images/About-bg0.jpg"));
scrollView = new UIScrollView (new RectangleF (0, 0, 320, 450));
        scrollView.ContentSize = new SizeF (320, 640 + 508 + 1000);
        //scrollView.BackgroundColor = UIColor.FromPatternImage (UIImage.FromFile ("Images/About-bg0.jpg"));
        scrollView.BackgroundColor = UIColor.Clear;
like image 22
Pavel Sich Avatar answered Sep 29 '22 18:09

Pavel Sich


After some quick googleing I found two links that will help you:

Google Groups discussion on this question
Blog post on how to do this.

like image 38
Kredns Avatar answered Sep 29 '22 16:09

Kredns