Search code examples
iosswiftuiimageviewresearchkit

iOS research kit survey (swift)


how can I add a custom background to my ResearchKit survey?

I tried:

taskViewController.view.backgroundColor = UIColor(patternImage: UIImage(named:imageName))

And:

    taskViewController.view.backgroundColor = UIColor.clearColor()
    let backgroundImage = UIImage(named: "Background")
    let imageView = UIImageView(image: backgroundImage)
    taskViewController.view.addSubview(imageView)
    taskViewController.view.sendSubviewToBack(imageView)

Solution

  • The individual step view controllers will each need the background added. There is a delegate method taskViewController:stepViewControllerWillAppear:, which you can use to intercept the step view controller before presentation and modify its view hierarchy as needed. Nite that many of the steps include a table view or scroll view in their view hierarchy, which you would need to take into account.

    If all you want is background color, you could try using UIView appearanceWhenContainedIn to change background color on the whole hierarchy below each step view controller.