I have a custom view (xib
) that has a UIButton
inside of it, I made id IBDesignable
doing the following:
UserView.swift
import UIKit
@IBDesignable
class UserView: UIView {
@IBOutlet var view: UIView!
@IBOutlet weak var userButton: UIButton!
override init(frame: CGRect) {
super.init(frame: frame)
load()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
load()
}
fileprivate func load() {
Bundle.main.loadNibNamed("UserView", owner: self, options: nil)
addSubview(view)
self.frame = bounds
}
}
UserView.xib
- Added the UIButton and set constraints
- Set the File's Owner:
UserView
Storyboard
I added a UIView to a Bar Button Item
and assigned UserView class but nothing is rendering, and I got the following build error:
error: IB Designables: Failed to render and update auto layout status for FoodViewController (bR3-Kz-wX7): The agent threw an exception.
My currently environment: Xcode 9, Swift 4
I'm cringing at how dumb this is that doing what I'm about to tell you makes a difference, but you can try removing the breaking code out of
and only use it in
. I'm cringing, even more, when I report that its possible that your changes could still reflect in storyboard as desired when doing this.
You can identify the breaking code by commenting out all the lines and using a process of elimination to identify the breaking line.