Open winterlovesong opened 10 years ago
Hi @winterlovesong ,
Do you want to have a static background (same bg for all your page) or a background to each page ?
Same background for all pages
Simply set view.backgroundColor
property of your ViewPager
subclass in -viewDidLoad
method and for every content view controller you give to the data source of ViewPager
set
viewController.view.backgroundColor = [UIColor clearColor];
and everything should be fine.
P.S. forgive me for responding so late, I'm having tough times lately.
Thanks, it's working but I don't why it get pixelated?
What is it that pixelated?
the background image looks blurred like this
Your device is 4" retina and you should set a background image of the appropriate resolution, 640 by 1136 pixels.
sure, the image is 640 x 1136 pixels. I have both the @2x and the regular one.
Well then the best guess is it's somehow setting the regular one. How are you setting the background image? Can you show me that part of the code?
//Background
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"home-background"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
You're drawing it, not setting it.
Instead try;
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"home-background"];
You can also set it by drawing but you need to do a few more things to support retina resolution.
Hey man, thanks. Everything works fine.
You're welcome :+1:
Hey just another issue, you know what are those thin gray lines in the viewpager controller ?
They are just separators. There isn't a public way to disable them (for now), but you can disable them by commenting out the related lines from ViewPagerController.m
They're in this -drawRect:
method and applied to all tabs.
https://github.com/iltercengiz/ICViewPager/blob/master/ICViewPager/ICViewPager/ViewPagerController.m#L80
Hi,
How to set background image in ViewPagerController Class?
Thank you!