I have a CustomClass.swift and a CustomClass.xib. I want XCode's Interface Builder to render views of class CustomClass using the provided .xib-File. Just like it does when I run the app.
I am using XCode 8.3.2 (8E2002)
import UIKit
@IBDesignable class forceInterface: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
Bundle.main.loadNibNamed("forceInterface", owner: self, options: nil)
self.addSubview(view)
view.frame = self.bounds
}
@IBOutlet var view: UIView!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var progressView: UIProgressView!
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
}
}
File owner is set to CustomClass. It contains a UIView that contains a UISwitch and a UILabel.

The problem is that, eventhough I have @IBDesignable in my CustomClass.swift, it isn't rendering in the InterfaceBuilder. I am placing a UIView there and setting its class to CustomClass:

As you can see, it even says Designables: Up to date in the inspector. But I am not seeing anything.
When running the app everything works as expected!
Why are you doing this
self.addSubview(view)
view.frame = self.bounds
You should assign the views' frame before you add it as a subview to its superview
view.frame = self.bounds
self.addSubview(view)
I am not sure why you view is not loading even though you have assigned it as IBDesignable. I normally use these steps to troubleshoot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With