iltercengiz / ICViewPager

MIT License
955 stars 235 forks source link

Background image #68

Open winterlovesong opened 10 years ago

winterlovesong commented 10 years ago

Hi,

How to set background image in ViewPagerController Class?

Thank you!

charliefancelli commented 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 ?

felipeS commented 10 years ago

Same background for all pages

iltercengiz commented 10 years ago

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.

felipeS commented 10 years ago

Thanks, it's working but I don't why it get pixelated?

iltercengiz commented 10 years ago

What is it that pixelated?

felipeS commented 10 years ago

the background image looks blurred like this image

iltercengiz commented 10 years ago

Your device is 4" retina and you should set a background image of the appropriate resolution, 640 by 1136 pixels.

felipeS commented 10 years ago

sure, the image is 640 x 1136 pixels. I have both the @2x and the regular one.

iltercengiz commented 10 years ago

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?

felipeS commented 10 years ago
//Background
UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"home-background"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];
iltercengiz commented 10 years ago

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.

felipeS commented 10 years ago

Hey man, thanks. Everything works fine.

iltercengiz commented 10 years ago

You're welcome :+1:

felipeS commented 10 years ago

Hey just another issue, you know what are those thin gray lines in the viewpager controller ?

iltercengiz commented 10 years ago

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

iltercengiz commented 10 years ago

They're in this -drawRect: method and applied to all tabs. https://github.com/iltercengiz/ICViewPager/blob/master/ICViewPager/ICViewPager/ViewPagerController.m#L80