ios - Addsubview custom xib file error -
i'm using swift 3, have error adding xib file subview
let bundle = bundle(for: type(of: self)) let nib = uinib(nibname: "customview", bundle: bundle) let view = nib.instantiate(withowner: self, options: nil)[0] as! uiview view.frame = bounds view.autoresizingmask = [.flexiblewidth, .flexibleheight] self.addsubview(view);
can me please?
in custom view class implemented follow:
import uikit @ibdesignable class testview: uiview { override init(frame: cgrect) { super.init(frame: frame) loadviewfromnib() } required init?(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } func loadviewfromnib(){ let view = bundle.main.loadnibnamed("test", owner: self, options: nil)?.first as! uiview print(view.backgroundcolor ?? uicolor.blue) } }
then in viewcontroller want add custom view write below:
let view = testview()
and dont find crash.
Comments
Post a Comment