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 imag开发者_如何学Ce 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.
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.
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"]]];
I restarted XCode and it worked!
精彩评论