Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IBDesignable UI is not showing in Xcode 9 with Swift

I trying to using my custom xib files. But those UI are not showing in main view controller in xcode. But it show when run the app. I already added @IBDesignable in class. Here is what i did.

  1. I created TestView.xib and added some design

  2. I created TestView.swift

  3. I updated fileOwner of TestView.xib with TestView in Custom Class

  4. I added init code to testView.swift

Code inside TestView.swift

import UIKit

@IBDesignable class DetailView: UIView {

override init(frame: CGRect){
    super.init(frame: frame)
    self.setup()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
    self.setup()

}

func setup() {
    let view = Bundle.main.loadNibNamed("TestView", owner: self, options: nil)?.first as! UIView
    view.frame = self.bounds
    self.addSubview(view)
}

}
  1. And Added on UIView in MainViewController and link to TestView with custom class name.

  2. After that i run the app, I can see the UI from testView. Image of emulator and result

  3. But my custom UI don't show in MainViewController in xcode Image of xcode view controller

How can i enable to see my custom UI in MainViewController ? Thanks

like image 914
Thet Paing Soe Avatar asked Sep 01 '25 16:09

Thet Paing Soe


1 Answers

In InterfaceBuilder select your ViewController and choose "Editor-->Refresh all Views". Then your custom view should come up.

If something is wrong you can debug your IBDesignable class by setting breakpoints in your code and then choose "Editor-->Debug selected views".

prepareForInterfaceBuilder() only needs to be implemented if you need special design appearance in InterfaceBuilder.

Sometimes it is necessary to clean the project and build folder to get it to work:
Project->Clean
Project->(hold down options key)->Clean Build Folder

like image 160
zisoft Avatar answered Sep 04 '25 05:09

zisoft