Umair A.
Umair A.

Reputation: 6873

iPhone UIScroll Fixed Background Not Working

I have an iPhone app where I have a view and following hierarchy.

View
   ImageView
   ScrollView
      OtherItems

I have ImageView background set to an image and ScrollView color to clearColor but still the background is white in simulator and iphone both. Why is that so? Although I can see the background in the IB.

Upvotes: 0

Views: 785

Answers (3)

Umair A.
Umair A.

Reputation: 6873

I restarted XCode and it worked!

Upvotes: 0

Herz Rod
Herz Rod

Reputation: 831

Maybe your "Other Items" have the background set to whiteColor ... Or you can set the backgroundColor of the scrollView to the image in code.

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

Also, if you have a large image or your scrollView remains in memory a long time, you shouldn't use the imageNamed: method because it caches the image and drains memory; you should use imageWithContentsOfFile: instead.

scroll.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]];

Upvotes: 1

PengOne
PengOne

Reputation: 48398

Step 1: Check that the image name is exactly correct (case sensitive) and that the image file has been added to the project.

Step 2: Set the imageView image to a color and see if anything changes. If yes, double check step 1. If no, post some code.

Upvotes: 1

Related Questions