-2

In my AppDelegate.swift-class I added the following:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.navController.pushViewController(rootViewController, animated: false)
    self.createSlideOutMenu(navController, rearViewController: menuViewController)
    self.window?.makeKeyAndVisible()
    return true
}

and the method:

func createSlideOutMenu(frontViewController: UIViewController, rearViewController: UIViewController) {

        // create instance of swRevealViewController based on frontViewController and rearViewController
        let swRevealViewController = SWRevealViewController(rearViewController: rearViewController, frontViewController: frontViewController)
        swRevealViewController.toggleAnimationType = SWRevealToggleAnimationType.EaseOut
        swRevealViewController.toggleAnimationDuration = 0.3

        // change background color
        swRevealViewController.frontViewController.view.backgroundColor = UIColor.whiteColor()
        swRevealViewController.rearViewController.view.backgroundColor = UIColor.whiteColor()

        // set swRevealViewController as rootViewController of windows
        self.window?.rootViewController = swRevealViewController
}

When I switch to a new ViewController the background is always black. I tried to change to color in the navController but nothing happened. How can the background color of the ViewControllers can be change to i.e. white?

Fogmeister
  • 76,236
  • 42
  • 207
  • 306
manu
  • 556
  • 2
  • 9
  • 29

1 Answers1

1

OK, the problem here is one of responsibility of code.

First off, the code that you posted in your question is entirely irrelevant.

What you are doing is presenting the AnatomyViewController when the selected menu is pressed.

However, you look at the code there and there is nothing setting the background colour or anything.

Second, if you want a view controller to have a white background colour then add this line TO THAT VIEW CONTROLLER.

view.backgroundColor = UIColor.yellowColor()

Let the view controller deal with what colour it should be.

If you want things like the navigation stuff you'll need to create that also. At the moment you're just presenting a single view controller.

Fogmeister
  • 76,236
  • 42
  • 207
  • 306