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); 

enter image description here

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

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -