0

I has one initial view controller in my story board here is the code:

import UIKit

class ViewController: UIViewController {


@IBOutlet weak var textField: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

   let customview = customUI()

    textField.inputView = customview.view
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

}

in the customUI class I have this code :

import UIKit

class customUI : UIViewController {

    override func viewDidLoad() {

        super.viewDidLoad()

    }

}

Then I create another viewController in storyboard and set the class to be customUI class. Then I choose its background color in storyboard to be blue.

Then I run the simulator, and click on the textField. it loads the plain grey area instead of the blue background that I have set.

Why? how to fix this? I'm new to UI in Xcode.

some people talking about this issue in Objective-C but I know only swift, please give me detail explanation in swift.

Team
  • 587
  • 2
  • 9
  • 21
  • 1
    I think you should check out this post: http://stackoverflow.com/questions/27276561/swift-adding-a-view-controller-as-a-subview-in-another-view-controller – Laffen Nov 02 '15 at 08:25

1 Answers1

2

When you create the customview object it does not have any connection with your storyboard, you need to do:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let customview = storyboard.instantiateViewControllerWithIdentifier("SIDCustomUI") as! customUI

where SIDCustomUI is Storyboard ID for your ViewController

Alexey Pichukov
  • 3,377
  • 2
  • 19
  • 22