in objective c it can be done in init method by
-(id)init{
self = [[[NSBundle mainBundle] loadNibNamed:@\"ViewBtnWishList\" owner:0 options:nil] obje
Just subclass this simple class (swift 5):
open class NibView: UIView {
open override func awakeAfter(using coder: NSCoder) -> Any? {
if subviews.count == 0 {
return UINib(nibName: "\(Self.self)", bundle: nil).instantiate(withOwner: nil, options: nil)[0] as! UIView
}
return self
}
}
class CustomView: NibView {
}
As others pointed out, set File's Owner to your CustomView class (not xib's root view itself). Then set custom class to CustomView to any view that you want to be replaced by your custom view class. Also, autolayout respects all constraints inside your xib, at least as a subview of a UITableViewCell's content view. Not sure about other cases.
As simple, as it happens to be, somehow Apple did another quest for us for such a basic thing! What a wonderful company! Never gonna be bored with them!