Edward An
Edward An

Reputation: 1737

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?

Upvotes: 13

Views: 33464

Answers (5)

Jayprakash Dubey
Jayprakash Dubey

Reputation: 36447

This one worked for me...

self.scrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tileableImage.png"]];

Upvotes: 1

user1456898
user1456898

Reputation:

Have you tried this,

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"content.png"]];

Upvotes: 2

jhabbott
jhabbott

Reputation: 19301

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];

Upvotes: 19

Pavel Sich
Pavel Sich

Reputation: 1299

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;

Upvotes: 9

Kredns
Kredns

Reputation: 37211

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.

Upvotes: 2

Related Questions