Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a background image to UIScrollView

I have a UIScrollView added to a UIView. Now i have added a background image to the scrollVIew.

The image has a fixed size like 320X460. But when the scroll view scrolls further down i can see white colour areas on the scroll view.

How could i prevent this ?

I tried adding the image to the view, and making the scrollview background as clearColor, but it doesn't work.

[scrollView addSubView:imageView];

self.view = scrollview;

[scrollview setBackgroundColor:[UIColor clearColor]];
like image 394
Illep Avatar asked Feb 16 '12 16:02

Illep


2 Answers

Try setting a tileable image as your background color.

scrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tileableImage.png"]];
like image 70
commanda Avatar answered Nov 14 '22 01:11

commanda


If you don't want to tile an image, insert the image view:

[webView insertSubview:backgroundImage atIndex:0];

Then set it's size to match the webView at creation or in viewWillLayoutSubviews.

like image 42
TigerCoding Avatar answered Nov 13 '22 23:11

TigerCoding