Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController with one constant background image

I want a PageViewController that just has one constant background. Kind of similar to the tutorial in Evernote's iOS app.

I was thinking about making the UIPageViewController's background transparent and each view in the page controller transparent as well but I don't think its working.

Any ideas?

like image 869
AndrewSB Avatar asked Feb 21 '15 20:02

AndrewSB


2 Answers

On your UIPageViewController add the UIImageView definition on top (Swift):

var imageView: UIImageView?

And then in viewDidLoad: add:

imageView = UIImageView(image: UIImage(named: "background")!)
imageView!.contentMode = .ScaleAspectFill
view.insertSubview(imageView!, atIndex: 0)
like image 88
Markus Rautopuro Avatar answered Nov 18 '22 01:11

Markus Rautopuro


I've made some edits and added some notes to your project which can be found here

Just reiterating those notes:

  • Create imageView with screen view bounds
  • Set contentMode to .ScaleAspectFit to avoid image distortion.
  • Similarly, you can use .ScaleAspectFill if your image's aspect ratio differs from the view's aspect ratio
  • Add the imageView as a subview and send it to the back so that it doesn't cover your Tutorial views
  • In Main.storyboard, i've removed the tutorialViewController's view background image and set the background color to .clearColor()
like image 6
Sean Avatar answered Nov 18 '22 01:11

Sean